[OpenJDK 2D-Dev] [9] Review request for 8167102: [macosx] PrintRequestAttributeSet breaks page size set using PageFormat (original) (raw)

Anton Litvinov anton.litvinov at oracle.com
Fri Mar 17 17:29:39 UTC 2017


Hello,

Could you please review the following fix for the bug.

Bug: https://bugs.openjdk.java.net/browse/JDK-8167102 Webrev: http://cr.openjdk.java.net/~alitvinov/8167102/jdk9/webrev.00

The bug consists in the fact that, if the user's application specifies the required page size (media size) through "java.awt.print.PrinterJob" API particularly via "java.awt.print.PageFormat" instance supplied to the method "PrinterJob.setPrintable(Printable, PageFormat)" and calls "PrinterJob.print(PrintRequestAttributeSet)" with "javax.print.attribute.PrintRequestAttributeSet" containing at least 1 any "PrintRequestAttribute", then the page or pages will be printed with "PageFormat" describing the default page size of the printer which is different from the expected and originally set by the user's application "PageFormat".

Debugging showed that the new "PageFormat" with unexpected media size is created in the method "sun.print.RasterPrinterJob.getPageFormatFromAttributes()" which is invoked from the native function "jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m::javaPrinterJobToNSPrintInfo". The method "RasterPrinterJob.getPageFormatFromAttributes()" returns a new "PageFormat" always, if the provided by the user "PrintRequestAttributeSet" is not empty, and the default values are set to particular instance variables of this "PageFormat", if "PrintRequestAttributeSet" does not contain the searched "OrientationRequested", "MediaSizeName", "MediaPrintableArea" attributes.

THE SOLUTION: Although it is clearly stated in Java Platform SE 8 API Specification (documentation of the method "PrinterJob.print(PrintRequestAttributeSet)") Specification URL: http://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html#print-javax.print.attribute.PrintRequestAttributeSet-

that media size, orientation and imageable area attributes specified in "PrintRequestAttributeSet" supplied to the method "PrinterJob.print" will be used for construction of a new "PageFormat", which will be passed to "Printable" object, instead of the original "PageFormat" instance set through "PrinterJob.setPrintable" method, the observed in this issue behavior is a bug, because in the bug test case neither media size, nor orientation, nor imageable area attributes are specified in "PrintRequestAttributeSet".

The fix alters the method "sun.print.RasterPrinterJob.getPageFormatFromAttributes()" to use corresponding values from "PageFormat" instance originally set through "PrinterJob" API during construction of the new "PageFormat", when it is found out that "OrientationRequested", or "MediaSizeName", or "MediaPrintableArea" attribute is not specified in "PrintRequestAttributeSet" supplied to "PrinterJob.print" method.

Thank you, Anton



More information about the 2d-dev mailing list