On Fri, 25 Jul 2025 21:16:38 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

>> Christian Heilmann has updated the pull request with a new target base due 
>> to a merge or a rebase. The incremental webrev excludes the unrelated 
>> changes brought in by the merge/rebase. The pull request contains five 
>> additional commits since the last revision:
>> 
>>  - 8297191 fixed printing page range for e.g. page 2 to 2 on macOS
>>  - 8297191 fixed printing page range for e.g. page 2 to 2 on macOS
>>  - Merge branch 'master' of https://github.com/openjdk/jdk into pr/11266
>>  - Merge branch 'master' into pr/11266
>>  - 8297191 fixed printing page range for e.g. page 2 to 2 on macOS
>
> src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m line 149:
> 
>> 147:     else
>> 148:     {
>> 149:         aRange->length = fTotalPages;
> 
> But why didn't the old code work? If a range is set to 2-3, we know exactly 
> the number of pages to print, and this number is 2.
> 
> Does it work correctly if `mDocument.getNumberOfPages()` in 
> `CPrinterJob.java` returns a certain number instead of 
> `UNKNOWN_NUMBER_OF_PAGES`?

> However, the fix resets the known range of pages to the full range of the 
> document. Is it because the native code doesn't care about the range and it's 
> handled in Java side?

It looks like the operating system does not expect the page range selected by 
the user here, but the number of pages in the document, even though it is 
queried as page range.


> Wouldn't it be easier then to always return NO from knowsPageRange? The 
> fTotalPages field can be dropped from the PrinterView class.

Here we can only guess what exactly the operating system is doing in this case. 
For example, if the number of pages is not known, e.g. in streaming mode, the 
operating system must start with the first page and iterate through the pages 
until it reaches the desired page.
So I would let the operating system know the number of pages. It may help it to 
choose a more appropriate printing strategy.


> But why didn't the old code work? If a range is set to 2-3, we know exactly 
> the number of pages to print, and this number is 2.

To answer this question, we need to look at the code of the operating system. 
But it seems that the operating system needs the total number of pages here, 
not the range selected by the user.
The documentation page does not describe it in detail either.

> Does it work correctly if mDocument.getNumberOfPages() in CPrinterJob.java 
> returns a certain number instead of UNKNOWN_NUMBER_OF_PAGES?

I tried both variants and it does not work.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/11266#discussion_r2236415962

Reply via email to