8033277: Wrong scaling when printing in Canon Pixma ip100
authorjgodinez
Wed, 05 Feb 2014 14:59:00 -0800
changeset 23284 8d155a88e83d
parent 23283 fbd991796648
child 23285 ae856aaa48b0
8033277: Wrong scaling when printing in Canon Pixma ip100 Reviewed-by: prr, bae
jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java
jdk/test/javax/print/attribute/TestUnsupportedResolution.java
--- a/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java	Wed Feb 05 09:06:54 2014 -0800
+++ b/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java	Wed Feb 05 14:59:00 2014 -0800
@@ -701,7 +701,9 @@
                     setColorAttrib(attr);
                 }
                 else if (attr.getCategory() == PrinterResolution.class) {
-                    setResolutionAttrib(attr);
+                    if (myService.isAttributeValueSupported(attr, null, null)) {
+                        setResolutionAttrib(attr);
+                    }
                 }
                 else if (attr.getCategory() == PrintQuality.class) {
                     setQualityAttrib(attr);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/print/attribute/TestUnsupportedResolution.java	Wed Feb 05 14:59:00 2014 -0800
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/**
+ * @test
+ * @bug 8033277
+ * @summary Confirm that scaling of printout is correct.  Manual comparison with printout using a supported resolution is needed.
+ * @run main/manual TestUnsupportedResolution
+ */
+
+import java.awt.Graphics;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+
+import javax.print.*;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.standard.*;
+import javax.print.attribute.ResolutionSyntax;
+
+public class TestUnsupportedResolution implements Printable
+{
+public static void main(String[] args)
+{
+    System.out.println("USAGE: default or no args: it will test 300 dpi\n       args is \"600\" : it will test 600 dpi\n------------------------------------------------------\n");
+    TestUnsupportedResolution pt=new TestUnsupportedResolution();
+    pt.printWorks(args);
+}
+
+public void printWorks(String[] args)
+{
+    PrinterJob job=PrinterJob.getPrinterJob();
+    job.setPrintable(this);
+    PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();
+    PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI);
+    if (args.length > 0 && (args[0].compareTo("600") == 0)) {
+        pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI);
+        System.out.println("Adding 600 Dpi attribute");
+    } else {
+        System.out.println("Adding 300 Dpi attribute");
+    }
+    PrintService ps = job.getPrintService();
+    boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null);
+    System.out.println("Is "+pr+" supported by "+ps+"?    "+resolutionSupported);
+    if (resolutionSupported) {
+        System.out.println("Resolution is supported.\nTest is not applicable, PASSED");
+    }
+    settings.add(pr);
+    if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) {
+        settings.add(Fidelity.FIDELITY_TRUE);
+        System.out.println("Adding Fidelity.FIDELITY_TRUE attribute");
+   }
+
+   if (job.printDialog(settings))
+   {
+        try {
+            job.print(settings);
+        } catch (PrinterException e) {
+            e.printStackTrace();
+        }
+    }
+}
+
+public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
+{
+    if (pageIndex>0)
+    {
+        return NO_SUCH_PAGE;
+    }
+
+    StringBuffer s=new StringBuffer();
+    for (int i=0;i<10;i++)
+    {
+        s.append("1234567890ABCDEFGHIJ");
+    }
+
+    int x=(int) pageFormat.getImageableX();
+    int y=(int) (pageFormat.getImageableY()+50);
+    graphics.drawString(s.toString(), x, y);
+
+    return PAGE_EXISTS;
+}
+}
+