On Mon, 17 Jun 2024 05:54:37 GMT, Renjith Kannath Pariyangad <rkannathp...@openjdk.org> wrote:
> Hi Reviewers, > > This fix will resolve page range not printing proper pages if the rage begin > from 2 or above on Mac machines. > I have verified the manual range related tests like PageRanges.java, > ClippedImages.java and test.java and confirmed its fixing the issue. > > Please review and let me know your suggestions if any. I added some traces and ran the test `PageRanges.java` with and without your proposed changes. The diff: diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index 416a3ee002b..6ddf46896b2 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -33,6 +33,7 @@ import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Arrays; import java.util.concurrent.atomic.AtomicReference; import javax.print.*; @@ -325,6 +325,8 @@ public void print(PrintRequestAttributeSet attributes) throws PrinterException { lastPage = mDocument.getNumberOfPages() - 1; } } + System.out.println("print: firstPage = " + firstPage + "; " + + "lastPage = " + lastPage); try { synchronized (this) { @@ -338,7 +340,11 @@ public void print(PrintRequestAttributeSet attributes) throws PrinterException { : (PageRanges)attributes.get(PageRanges.class); int[][] prMembers = (pr == null) ? new int[0][0] : pr.getMembers(); int loopi = 0; + System.out.println("pr = " + pr); + System.out.println("prMembers = " + Arrays.deepToString(prMembers)); do { + System.out.println("printLoop: firstPage = " + firstPage + "; " + + "lastPage = " + lastPage); if (EventQueue.isDispatchThread()) { // This is an AWT EventQueue, and this print rendering loop needs to block it. The output: 2-3 + 3-5 without Renjith changes print: firstPage = 1; lastPage = 2 pr = 2-3 prMembers = [[2, 3]] printLoop: firstPage = 1; lastPage = 2 print: firstPage = 2; lastPage = 4 pr = 3-5 prMembers = [[3, 5]] printLoop: firstPage = 2; lastPage = 4 2-3 + 3-5 with Renjith changes print: firstPage = 0; lastPage = -1 pr = 2-3 prMembers = [[2, 3]] printLoop: firstPage = 0; lastPage = -1 print: firstPage = 0; lastPage = -1 pr = 3-5 prMembers = [[3, 5]] printLoop: firstPage = 0; lastPage = -1 In the first case, I got page 3 and page 5 printed; with Renjith's changes, I got the correct range printed 2-3 and 3-5. So it works… kind of. I believe the bug is somewhere in native code. What would be printed if `PageRanges` contains several ranges? This case should be supported as well. Since the last page to be printed is -1, `PrinterView->knowsPageRange` sets `aRange->length` to `NSIntegerMax`. This does not look right, even though it works. https://github.com/openjdk/jdk/blob/08ace27da1d9cd215c77471eabf41417ff6282d2/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m#L130-L152 Then, the Print dialog itself: with Renjith's changes the range of pages is preserved. Without the changes, the range of pages isn't preserved. It's a different bug: the dialog should be initialised using the attributes. If `PageRanges` attribute is set and is supported, the dialog should select **Range** radio button and set the correct page range. A new test could be written (if it doesn't exist already) to confirm whether attributes are taken into account when initialising the Print dialog and then a new bug should be submitted. ------------- PR Comment: https://git.openjdk.org/jdk/pull/19740#issuecomment-2182540891 PR Comment: https://git.openjdk.org/jdk/pull/19740#issuecomment-2182543047