src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java

Print this page

        

@@ -207,11 +207,10 @@
         /* Get the range of pages we are to print. If the
          * last page to print is unknown, then we print to
          * the end of the document. Note that firstPage
          * and lastPage are 0 based page indices.
          */
-        int numPages = mDocument.getNumberOfPages();
 
         int firstPage = getFirstPage();
         int lastPage = getLastPage();
         if(lastPage == Pageable.UNKNOWN_NUMBER_OF_PAGES) {
             int totalPages = mDocument.getNumberOfPages();

@@ -224,10 +223,16 @@
             synchronized (this) {
                 performingPrinting = true;
                 userCancelled = false;
             }
 
+            //Add support for PageRange
+            PageRanges pr = (attributes == null) ?  null 
+                                                 : (PageRanges)attributes.get(PageRanges.class);
+            int[][] prMembers = (pr == null) ? new int[0][0] : pr.getMembers();
+            int loopi = 0;
+            do {
             if (EventQueue.isDispatchThread()) {
                 // This is an AWT EventQueue, and this print rendering loop needs to block it.
 
                 onEventThread = true;
 

@@ -256,10 +261,15 @@
                     printLoop(true, firstPage, lastPage);
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
             }
+                if (++loopi < prMembers.length) {
+                    firstPage = prMembers[loopi][0]-1;
+                    lastPage = prMembers[loopi][1] -1;
+                }
+              }  while (loopi < prMembers.length);
         } finally {
             synchronized (this) {
                 // NOTE: Native code shouldn't allow exceptions out while
                 // printing. They should cancel the print loop.
                 performingPrinting = false;