8181659: Create an alternative fix for JDK-8167102, whose fix was backed out
authoralitvinov
Sun, 03 Dec 2017 13:21:41 +0000
changeset 48268 baad9dc0eab1
parent 48267 2469e21060a0
child 48269 40afd72303e9
8181659: Create an alternative fix for JDK-8167102, whose fix was backed out Reviewed-by: prr, serb
src/java.desktop/share/classes/sun/print/RasterPrinterJob.java
test/jdk/java/awt/print/PageFormat/WrongPaperPrintingTest.java
--- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java	Fri Dec 01 17:44:07 2017 -0800
+++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java	Sun Dec 03 13:21:41 2017 +0000
@@ -886,12 +886,45 @@
         }
    }
 
-   protected PageFormat getPageFormatFromAttributes() {
-       if (attributes == null || attributes.isEmpty()) {
+    protected PageFormat getPageFormatFromAttributes() {
+        if (attributes == null || attributes.isEmpty()) {
             return null;
         }
-        return attributeToPageFormat(getPrintService(), this.attributes);
-   }
+
+        PageFormat newPf = attributeToPageFormat(
+            getPrintService(), attributes);
+        PageFormat oldPf = null;
+        Pageable pageable = getPageable();
+        if ((pageable != null) &&
+            (pageable instanceof OpenBook) &&
+            ((oldPf = pageable.getPageFormat(0)) != null)) {
+            // If orientation, media, imageable area attributes are not in
+            // "attributes" set, then use respective values of the existing
+            // page format "oldPf".
+            if (attributes.get(OrientationRequested.class) == null) {
+                newPf.setOrientation(oldPf.getOrientation());
+            }
+
+            Paper newPaper = newPf.getPaper();
+            Paper oldPaper = oldPf.getPaper();
+            boolean oldPaperValWasSet = false;
+            if (attributes.get(MediaSizeName.class) == null) {
+                newPaper.setSize(oldPaper.getWidth(), oldPaper.getHeight());
+                oldPaperValWasSet = true;
+            }
+            if (attributes.get(MediaPrintableArea.class) == null) {
+                newPaper.setImageableArea(
+                    oldPaper.getImageableX(), oldPaper.getImageableY(),
+                    oldPaper.getImageableWidth(),
+                    oldPaper.getImageableHeight());
+                oldPaperValWasSet = true;
+            }
+            if (oldPaperValWasSet) {
+                newPf.setPaper(newPaper);
+            }
+        }
+        return newPf;
+    }
 
 
    /**
--- a/test/jdk/java/awt/print/PageFormat/WrongPaperPrintingTest.java	Fri Dec 01 17:44:07 2017 -0800
+++ b/test/jdk/java/awt/print/PageFormat/WrongPaperPrintingTest.java	Sun Dec 03 13:21:41 2017 +0000
@@ -22,9 +22,8 @@
  */
 
 /* @test
-   @bug 8167102
+   @bug 8167102 8181659
    @summary PrintRequestAttributeSet breaks page size set using PageFormat
-   @ignore Exclude the test until 8167102 is resolved by a new reassessed fix
    @run main/manual WrongPaperPrintingTest
  */