RFR: 8297191: [macos] printing page range "page 2 to 2" or "page 2 to 4" on macOS leads to not print [v2]

Alexey Ivanov aivanov at openjdk.org
Fri Jul 25 21:33:09 UTC 2025


On Fri, 18 Jul 2025 13:19:10 GMT, Christian Heilmann <duke at openjdk.org> wrote:

>> This PR fixes a bug that caused no or the wrong set of pages to be printed when using page ranges on macOS.
>> 
>> The main fix is to change the 'location' value of the returned NSRange from the knowsPageRange method to 1 in the native class PrinterView.m.
>
> 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

The suggested fix works.

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?

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

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`?

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

PR Review: https://git.openjdk.org/jdk/pull/11266#pullrequestreview-3056811385
PR Review Comment: https://git.openjdk.org/jdk/pull/11266#discussion_r2232022179


More information about the client-libs-dev mailing list