[OpenJDK 2D-Dev] [12] Review request for 8201818: [macosx] Printing attributes break page size set via "java.awt.print.Book" object

Anton Litvinov anton.litvinov at oracle.com
Fri Aug 17 19:42:34 UTC 2018


Could you please review the following fix for the bug.

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

The bug consists in the fact that, if any one printing attribute is 
contained in "PrintRequestAttributeSet" during the call to 
"java.awt.print.PrinterJob.print(PrintRequestAttributeSet)" method, a 
page size from "java.awt.print.PageFormat" object provided by 
"java.awt.print.Book" set to a printer job through 
"PrinterJob.setPageable(Pageable)" method is not respected and the 
printer job prints the document on a page of a size equal to a default 
page size of a selected printer.

The root cause of the bug is 
"sun.print.RasterPrinterJob.getPageFormatFromAttributes()" method which 
returns "PageFormat" object constructed from default settings of the 
selected printer, if the attribute set in the printer job is not empty. 
For the case in this bug, when the user explicitly sets "Book" object 
for the printer job, this method should not return anything except for 
"null", because:

1. According to the documentation for the method 
"PrinterJob.print(PrintRequestAttributeSet)" from Java Platform SE 8 API 
Specification, if a user sets "java.awt.print.Pageable" object for 
"PrinterJob", then printing attributes related to media size, imageable 
area, page orientation will not influence anyhow the "PageFormat" object 
used for printing, and only "PageFormat" provided by the "Pageable" 
object will be used.
Statement: "For clients of the Pageable interface, the PageFormat will 
always be as supplied by that interface, on a per page basis."
Specification URL #1: 

2. Documentation on the method 
"PrinterJob.printDialog(PrintRequestAttributeSet)" acknowledges the 
point #1 by the statement "If using the Pageable interface, clients 
which intend to use media selected by the user must create a PageFormat 
derived from the user's selections.".
Specification URL #2: 

The solution consists in changing the method 
"RasterPrinterJob.getPageFormatFromAttributes()" to return "null" for 
cases, when the "Pageable" object set in the printer job is not an 
instance of "sun.print.OpenBook" class, which is exclusively used by the 
printer job to wrap "Printable" object set by the user through 

The fix affects only macOS platform, because 
"RasterPrinterJob.getPageFormatFromAttributes()" method is called only 
from the macOS specific native code in the file 

Thank you,

More information about the 2d-dev mailing list