changeset 12554:d7e9bf2b16f4

8181659: Create an alternative fix for JDK-8167102, whose fix was backed out Reviewed-by: prr, serb
author alitvinov
date Mon, 04 Dec 2017 17:38:55 +0000
parents 50cb34f2217b
children 6bcb0cba6df6
files src/share/classes/sun/print/RasterPrinterJob.java test/java/awt/print/PageFormat/WrongPaperPrintingTest.java
diffstat 2 files changed, 38 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/print/RasterPrinterJob.java	Fri Nov 24 13:18:36 2017 +0530
+++ b/src/share/classes/sun/print/RasterPrinterJob.java	Mon Dec 04 17:38:55 2017 +0000
@@ -843,12 +843,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/java/awt/print/PageFormat/WrongPaperPrintingTest.java	Fri Nov 24 13:18:36 2017 +0530
+++ b/test/java/awt/print/PageFormat/WrongPaperPrintingTest.java	Mon Dec 04 17:38:55 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
  */