On Mon, 25 Aug 2025 19:38:15 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

>>> 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.
>
>> > 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.
> 
> You didn't answer the question, so I had to write a test which also uses 
> `Pageable` and returns the number of pages.
> 
> No, it doesn't work as expected *without* your suggested fix.
> 
> Yes, it does behave as expected *with* the fix. We're good.

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

Returning `NO` doesn't work at all. I had to test it myself. I get an error 
message dialog displayed: *Error while printing.*

Yet I still think the `fTotalPages` field can be dropped from the `PrinterView` 
class. It serves no real purpose and its value is often incorrect. For example, 
if the total number of pages returned by `Pageable` is 10, the value of 
`fTotalPages` is set to 10 too, even if the range 10-10 is requested.

I tested that setting `aRange->length` to `NSIntegerMax` always works. 
Therefore, the code can be simplified by getting rid of `fTotalPages`.

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

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

Reply via email to