Path: blob/master/test/jdk/javax/print/attribute/TestUnsupportedResolution.java
41149 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/**25* @test26* @bug 803327727* @summary Confirm that scaling of printout is correct. Manual comparison with printout using a supported resolution is needed.28* @run main/manual TestUnsupportedResolution29*/3031import java.awt.Graphics;32import java.awt.print.PageFormat;33import java.awt.print.Printable;34import java.awt.print.PrinterException;35import java.awt.print.PrinterJob;3637import javax.print.*;38import javax.print.attribute.HashPrintRequestAttributeSet;39import javax.print.attribute.PrintRequestAttributeSet;40import javax.print.attribute.standard.*;41import javax.print.attribute.ResolutionSyntax;4243public class TestUnsupportedResolution implements Printable44{45public static void main(String[] args)46{47System.out.println("USAGE: default or no args: it will test 300 dpi\n args is \"600\" : it will test 600 dpi\n------------------------------------------------------\n");48TestUnsupportedResolution pt=new TestUnsupportedResolution();49pt.printWorks(args);50}5152public void printWorks(String[] args)53{54PrinterJob job=PrinterJob.getPrinterJob();55job.setPrintable(this);56PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();57PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI);58if (args.length > 0 && (args[0].compareTo("600") == 0)) {59pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI);60System.out.println("Adding 600 Dpi attribute");61} else {62System.out.println("Adding 300 Dpi attribute");63}64PrintService ps = job.getPrintService();65boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null);66System.out.println("Is "+pr+" supported by "+ps+"? "+resolutionSupported);67if (resolutionSupported) {68System.out.println("Resolution is supported.\nTest is not applicable, PASSED");69}70settings.add(pr);71if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) {72settings.add(Fidelity.FIDELITY_TRUE);73System.out.println("Adding Fidelity.FIDELITY_TRUE attribute");74}7576if (job.printDialog(settings))77{78try {79job.print(settings);80} catch (PrinterException e) {81e.printStackTrace();82}83}84}8586public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException87{88if (pageIndex>0)89{90return NO_SUCH_PAGE;91}9293StringBuffer s=new StringBuffer();94for (int i=0;i<10;i++)95{96s.append("1234567890ABCDEFGHIJ");97}9899int x=(int) pageFormat.getImageableX();100int y=(int) (pageFormat.getImageableY()+50);101graphics.drawString(s.toString(), x, y);102103return PAGE_EXISTS;104}105}106107108