1 /* 2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4509958 27 * @summary Tests that the empty areas aren't drawn. 28 * @run main EmptyFill 29 */ 30 31 import java.io.*; 32 import java.awt.*; 33 import java.awt.geom.*; 34 import java.awt.print.*; 35 import javax.print.*; 36 import javax.print.attribute.*; 37 38 public class EmptyFill implements Printable { 39 print(Graphics g, PageFormat pf, int pageIndex)40 public int print(Graphics g, PageFormat pf, int pageIndex) { 41 42 if (pageIndex > 0) { 43 return Printable.NO_SUCH_PAGE; 44 } 45 46 g.setColor(Color.black); 47 48 int[] xq = { 75, 125, 75 }; 49 int[] yq = { 140, 140, 140}; 50 51 g.fillPolygon( xq, yq, 3 ); 52 53 return Printable.PAGE_EXISTS; 54 } 55 main(String arg[])56 public static void main(String arg[]) throws Exception { 57 58 DocFlavor psFlavor = new DocFlavor("application/postscript", 59 "java.io.OutputStream"); 60 61 StreamPrintServiceFactory[] spfs = 62 PrinterJob.lookupStreamPrintServices("application/postscript"); 63 64 if (spfs.length == 0) { 65 return; 66 } 67 ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); 68 StreamPrintService svc = spfs[0].getPrintService(baos); 69 70 PrinterJob pj = PrinterJob.getPrinterJob(); 71 if (svc == null) { 72 return; 73 } 74 pj.setPrintService(svc); 75 pj.setPrintable(new EmptyFill()); 76 pj.print(); 77 78 String outStr = baos.toString("ISO-8859-1"); 79 if (outStr.indexOf("\nfill\n") > 0) { 80 throw new Exception("Expected no fills"); 81 } 82 } 83 } 84