RFR: 8251928: [macos] the printer DPI always be 72, cause some content lost when print out [v5]
Phil Race
prr at openjdk.org
Thu Sep 4 22:15:09 UTC 2025
On Thu, 4 Sep 2025 17:42:20 GMT, GennadiyKrivoshein <duke at openjdk.org> wrote:
>> The fix for the https://bugs.openjdk.org/browse/JDK-8251928.
>>
>> **Description**.
>> This PR contains changes to be able to print with DPI higher than 72 on macOS, set default CPrinterJob DPI is 300 like in the PSPrinterJob.
>>
>> As described in the macOS drawing guide, the following steps are required to draw with high DPI (https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-BCICIJAJ):
>> 1. Convert the user-space point, size, or rectangle value to device space coordinates;
>> 2. Normalize the value in device space so that it is aligned to the appropriate pixel boundary;
>> 3. Convert the normalized value back to user space;
>> 4. Draw your content using the adjusted value.
>>
>> The 1-st step is now implemented in the CPrinterJob, a Graphics provided to the print method adjusted to a printer's DPI.
>> The 2-nd step is a drawing process in the java code (without changes).
>> The 3-rd step is now implemented in the PrinterView.m, the drawing scaled back to the 72 DPI.
>> The 4-th step is a drawing process in the native code (without changes).
>>
>> **Tests**.
>> I run all tests from javax.print package and there is no any regression.
>> New test covers macOS and Linux only because we know its default DPI - 300.
>
> GennadiyKrivoshein has updated the pull request incrementally with one additional commit since the last revision:
>
> revert CGraphicsDevice.m constants. Update orientation constant usage
src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java line 470:
> 468: @Override
> 469: protected double getXRes() {
> 470: return hRes;
I have been unable to verify that this would be applied with a real printer device resolution, because my printer is not reporting PrinterResolution. Not sure why. I see it in the PPD but the call to the cups ppd API isn't finding it.
Thinking about it, this is may be the "real" problem if something in this API used to work but has stopped working.
src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java line 795:
> 793: return scaledPage;
> 794: }
> 795:
This is something of an abuse of these APIs which are *specified* to have sizes in 1/72"
This is all needed here because createData takes a PageFormat.
I looked and unless I am missing something all it ever does is use the bounds to return those (now larger) device bounds.
I would consider it a better approach to modify CPrinterSurfaceData.createData to accept what it really needs .. the device bounds. I don't see that it needs a page format.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25489#discussion_r2323636048
PR Review Comment: https://git.openjdk.org/jdk/pull/25489#discussion_r2323180760
More information about the client-libs-dev
mailing list