1 /* 2 * Copyright (c) 2014 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 /** 26 * @test 27 * @bug 8033277 28 * @summary Confirm that scaling of printout is correct. Manual comparison with printout using a supported resolution is needed. 29 * @run main/manual TestUnsupportedResolution 30 */ 31 32 import java.awt.Graphics; 33 import java.awt.print.PageFormat; 34 import java.awt.print.Printable; 35 import java.awt.print.PrinterException; 36 import java.awt.print.PrinterJob; 37 38 import javax.print.*; 39 import javax.print.attribute.HashPrintRequestAttributeSet; 40 import javax.print.attribute.PrintRequestAttributeSet; 41 import javax.print.attribute.standard.*; 42 import javax.print.attribute.ResolutionSyntax; 43 44 public class TestUnsupportedResolution implements Printable 45 { 46 public static void main(String[] args) 47 { 48 System.out.println("USAGE: default or no args: it will test 300 dpi\n args is \"600\" : it will test 600 dpi\n------------------------------------------------------\n"); 49 TestUnsupportedResolution pt=new TestUnsupportedResolution(); 50 pt.printWorks(args); 51 } 52 53 public void printWorks(String[] args) 54 { 55 PrinterJob job=PrinterJob.getPrinterJob(); 56 job.setPrintable(this); 57 PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet(); 58 PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI); 59 if (args.length > 0 && (args[0].compareTo("600") == 0)) { 60 pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI); 61 System.out.println("Adding 600 Dpi attribute"); 62 } else { 63 System.out.println("Adding 300 Dpi attribute"); 64 } 65 PrintService ps = job.getPrintService(); 66 boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null); 67 System.out.println("Is "+pr+" supported by "+ps+"? "+resolutionSupported); 68 if (resolutionSupported) { 69 System.out.println("Resolution is supported.\nTest is not applicable, PASSED"); 70 } 71 settings.add(pr); 72 if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) { 73 settings.add(Fidelity.FIDELITY_TRUE); 74 System.out.println("Adding Fidelity.FIDELITY_TRUE attribute"); 75 } 76 77 if (job.printDialog(settings)) 78 { 79 try { 80 job.print(settings); 81 } catch (PrinterException e) { 82 e.printStackTrace(); 83 } 84 } 85 } 86 87 public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException 88 { 89 if (pageIndex>0) 90 { 91 return NO_SUCH_PAGE; 92 } 93 94 StringBuffer s=new StringBuffer(); 95 for (int i=0;i<10;i++) 96 { 97 s.append("1234567890ABCDEFGHIJ"); 98 } 99 100 int x=(int) pageFormat.getImageableX(); 101 int y=(int) (pageFormat.getImageableY()+50); 102 graphics.drawString(s.toString(), x, y); 103 104 return PAGE_EXISTS; 105 } 106 } 107