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