Hi,
The fix looks reasonable.
But we've touched the code being touched here quite recently and the history
there shows that this can be tricky to get right :
8167102: [macosx] PrintRequestAttributeSet breaks page size set using
PageFormat
caused
8181192: [macos] javafx.print.PrinterJob.showPrintDialog() hangs on macOS
so then we had
8181659: Create an alternative fix for JDK-8167102, whose fix was backed out
Is this new bug a regression caused by the previous fix ?
Have you verified the previous fix is still functional ?
What tests have been run ?
Can you make sure this works in the cases of
a) no dialog
b) swing dialog
c) native dialog.
-phil.
On 8/17/18, 12:42 PM, Anton Litvinov wrote:
Hello,
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.
CAUSE OF THE BUG:
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:
https://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html#print-javax.print.attribute.PrintRequestAttributeSet-
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:
https://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html#printDialog-javax.print.attribute.PrintRequestAttributeSet-
THE SOLUTION:
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
"PrinterJob.setPrintable(Printable)".
The fix affects only macOS platform, because
"RasterPrinterJob.getPageFormatFromAttributes()" method is called only
from the macOS specific native code in the file
"src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m".
Thank you,
Anton