On Fri, 30 May 2025 06:40:40 GMT, Prasanta Sadhukhan <psadhuk...@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.
>
> While running PDFBOX4935PrintDpi  testcase from the JBS, it is showing with 
> your fix
> ScaleX: 4.166666
> ScaleY: 4.166666
> DPI = 300
> 
> while printing to pdf. Shouldn't the scale be shown as 2.0 for retina display 
> while doing pdf printing?

@prsadhuk  , no, the scale should be 4.166666.

As described in the drawing guide
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-SW6

> Units in the user space are based on the printer's point, which was used in 
> the publishing industry to measure the size of content on the printed page. A 
> single point is equivalent to 1/72 of an inch. Points were adopted by earlier 
> versions of Mac OS as the standard resolution for content on the screen. OS X 
> continues to use the same effective “resolution” for user-space drawing.
> 
> Although a single point often corresponded directly to a pixel in the past, 
> in OS X, that may not be the case. Points are not tied to the resolution of 
> any particular device. If you draw a rectangle whose width and height are 
> exactly three points, that does not mean it will be rendered on the screen as 
> a three-pixel by three-pixel rectangle. On a 144 dpi screen, the rectangle 
> might be rendered using six pixels per side, and on a 600-dpi printer, the 
> rectangle would require 25 pixels per side. The actual translation from 
> points to pixels is device dependent and handled for you automatically by OS 
> X. 

So it does not matter what the actual device DPI is, we always use or see 72 on 
the java side.
I set the default printing DPI for macOS to 300 in this PR, so if you do not 
provide different value using javax.print.attribute.standard.PrinterResolution 
then the scaling should be 300/72 = 4.16666.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/25489#issuecomment-2922481400

Reply via email to