glib/poppler-page.cc            |   10 +++++---
 poppler/PSOutputDev.cc          |   50 +++++++++++++++++++++++-----------------
 poppler/PSOutputDev.h           |   14 ++++++-----
 qt4/src/poppler-ps-converter.cc |   11 ++++++--
 qt5/src/poppler-ps-converter.cc |   11 ++++++--
 utils/pdftops.cc                |   15 ++++++++----
 6 files changed, 71 insertions(+), 40 deletions(-)

New commits:
commit 9caf7525409d699c16896653528486451123b485
Author: Albert Astals Cid <[email protected]>
Date:   Sun Jan 4 18:48:02 2015 +0100

    Make PSOutputDev accept a list of pages indeces
    
    Instead of first, last
    
    Bug #84833
    
    Reviewed in the mailing list, see "Can anyone have a look at my patch?"

diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 6e2e7f8..db2387a 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1110,14 +1110,18 @@ poppler_page_render_to_ps (PopplerPage   *page,
   g_return_if_fail (POPPLER_IS_PAGE (page));
   g_return_if_fail (ps_file != NULL);
 
-  if (!ps_file->out)
+  if (!ps_file->out)  {
+    std::vector<int> pages;
+    for (int i = ps_file->first_page; i <= ps_file->last_page; ++i) {
+      pages.push_back(i);
+    }
     ps_file->out = new PSOutputDev (ps_file->filename,
                                     ps_file->document->doc,
-                                    NULL,
-                                    ps_file->first_page, ps_file->last_page,
+                                    NULL, pages,
                                     psModePS, (int)ps_file->paper_width,
                                     (int)ps_file->paper_height, 
ps_file->duplex,
                                     0, 0, 0, 0, gFalse, gFalse);
+  }
 
 
   ps_file->document->doc->displayPage (ps_file->out, page->index + 1, 72.0, 
72.0,
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 149bb62..b95df31 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2005 Martin Kretzschmar <[email protected]>
 // Copyright (C) 2005, 2006 Kristian Høgsberg <[email protected]>
-// Copyright (C) 2006-2009, 2011-2013 Albert Astals Cid <[email protected]>
+// Copyright (C) 2006-2009, 2011-2013, 2015 Albert Astals Cid <[email protected]>
 // Copyright (C) 2006 Jeff Muizelaar <[email protected]>
 // Copyright (C) 2007, 2008 Brad Hards <[email protected]>
 // Copyright (C) 2008, 2009 Koji Otani <[email protected]>
@@ -1074,7 +1074,7 @@ static void outputToFile(void *stream, const char *data, 
int len) {
 
 PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc,
                         char *psTitle,
-                        int firstPage, int lastPage, PSOutMode modeA,
+                        const std::vector<int> &pages, PSOutMode modeA,
                         int paperWidthA, int paperHeightA,
                          GBool noCropA, GBool duplexA,
                         int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
@@ -1136,7 +1136,7 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc 
*doc,
   }
 
   init(outputToFile, f, fileTypeA, psTitle,
-       doc, firstPage, lastPage, modeA,
+       doc, pages, modeA,
        imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA,
        paperWidthA, paperHeightA, noCropA, duplexA);
 }
@@ -1144,7 +1144,7 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc 
*doc,
 PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
                         char *psTitle,
                         PDFDoc *doc,
-                        int firstPage, int lastPage, PSOutMode modeA,
+                        const std::vector<int> &pages, PSOutMode modeA,
                         int paperWidthA, int paperHeightA,
                          GBool noCropA, GBool duplexA,
                         int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
@@ -1174,7 +1174,7 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void 
*outputStreamA,
   forceRasterize = forceRasterizeA;
 
   init(outputFuncA, outputStreamA, psGeneric, psTitle,
-       doc, firstPage, lastPage, modeA,
+       doc, pages, modeA,
        imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA,
        paperWidthA, paperHeightA, noCropA, duplexA);
 }
@@ -1214,7 +1214,7 @@ static bool pageDimensionEqual(int a, int b) {
 
 void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
                       PSFileType fileTypeA, char *pstitle, PDFDoc *docA,
-                      int firstPage, int lastPage, PSOutMode modeA,
+                      const std::vector<int> &pagesA, PSOutMode modeA,
                       int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
                       GBool manualCtrlA, int paperWidthA, int paperHeightA,
                       GBool noCropA, GBool duplexA) {
@@ -1222,7 +1222,12 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void 
*outputStreamA,
   PDFRectangle *box;
   PSOutPaperSize *size;
   GooList *names;
-  int pg, w, h, i;
+  int w, h, i;
+
+  if (pagesA.empty()) {
+    ok = gFalse;
+    return;
+  }
 
   // initialize
   displayText = gTrue;
@@ -1249,9 +1254,8 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void 
*outputStreamA,
   }
   Page *page;
   paperSizes = new GooList();
-  for (pg = (firstPage >= 1) ? firstPage : 1;
-       pg <= lastPage && pg <= catalog->getNumPages();
-       ++pg) {
+  for (size_t pgi = 0; pgi < pagesA.size(); ++pgi) {
+    const int pg = pagesA[pgi];
     page = catalog->getPage(pg);
     if (page == NULL)
       paperMatch = gFalse;
@@ -1313,8 +1317,11 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void 
*outputStreamA,
     imgURY = paperHeight;
   }
   manualCtrl = manualCtrlA;
+  std::vector<int> pages;
   if (mode == psModeForm) {
-    lastPage = firstPage;
+    pages.push_back(pagesA[0]);
+  } else {
+    pages = pagesA;
   }
   processColors = 0;
   inType3Char = gFalse;
@@ -1367,16 +1374,16 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void 
*outputStreamA,
   if (!manualCtrl) {
     Page *page;
     // this check is needed in case the document has zero pages
-    if ((page = doc->getPage(firstPage))) {
-      writeHeader(firstPage, lastPage,
+    if ((page = doc->getPage(pages[0]))) {
+      writeHeader(pages,
                  page->getMediaBox(),
                  page->getCropBox(),
                  page->getRotate(),
                  pstitle);
     } else {
-      error(errSyntaxError, -1, "Invalid page {0:d}", firstPage);
+      error(errSyntaxError, -1, "Invalid page {0:d}", pages[0]);
       box = new PDFRectangle(0, 0, 1, 1);
-      writeHeader(firstPage, lastPage, box, box, 0, pstitle);
+      writeHeader(pages, box, box, 0, pstitle);
       delete box;
     }
     if (mode != psModeForm) {
@@ -1387,7 +1394,7 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void 
*outputStreamA,
       writePS("%%EndProlog\n");
       writePS("%%BeginSetup\n");
     }
-    writeDocSetup(doc, catalog, firstPage, lastPage, duplexA);
+    writeDocSetup(doc, catalog, pages, duplexA);
     if (mode != psModeForm) {
       writePS("%%EndSetup\n");
     }
@@ -1463,7 +1470,7 @@ PSOutputDev::~PSOutputDev() {
   }
 }
 
-void PSOutputDev::writeHeader(int firstPage, int lastPage,
+void PSOutputDev::writeHeader(const std::vector<int> &pages,
                              PDFRectangle *mediaBox, PDFRectangle *cropBox,
                              int pageRotate, char *psTitle) {
   Object info, obj1;
@@ -1520,7 +1527,7 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage,
                  i==0 ? "DocumentMedia:" : "+", size->name, size->w, size->h);
     }
     writePSFmt("%%BoundingBox: 0 0 {0:d} {1:d}\n", paperWidth, paperHeight);
-    writePSFmt("%%Pages: {0:d}\n", lastPage - firstPage + 1);
+    writePSFmt("%%Pages: {0:d}\n", static_cast<int>(pages.size()));
     writePS("%%EndComments\n");
     if (!paperMatch) {
       size = (PSOutPaperSize *)paperSizes->get(0);
@@ -1603,7 +1610,7 @@ void PSOutputDev::writeXpdfProcset() {
 }
 
 void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog,
-                               int firstPage, int lastPage,
+                               const std::vector<int> &pages,
                                 GBool duplexA) {
   Page *page;
   Dict *resDict;
@@ -1611,7 +1618,7 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog 
*catalog,
   Object *acroForm;
   Object obj1, obj2, obj3;
   GooString *s;
-  int pg, i;
+  int i;
 
   if (mode == psModeForm) {
     // swap the form and xpdf dicts
@@ -1619,7 +1626,8 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog 
*catalog,
   } else {
     writePS("xpdf begin\n");
   }
-  for (pg = firstPage; pg <= lastPage; ++pg) {
+  for (size_t pgi = 0; pgi < pages.size(); ++pgi) {
+    const int pg = pages[pgi];
     page = doc->getPage(pg);
     if (!page) {
       error(errSyntaxError, -1, "Failed writing resources for page {0:d}", pg);
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index f30204d..262ce14 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2005 Martin Kretzschmar <[email protected]>
 // Copyright (C) 2005 Kristian Høgsberg <[email protected]>
-// Copyright (C) 2006-2008, 2012, 2013 Albert Astals Cid <[email protected]>
+// Copyright (C) 2006-2008, 2012, 2013, 2015 Albert Astals Cid <[email protected]>
 // Copyright (C) 2007 Brad Hards <[email protected]>
 // Copyright (C) 2009-2013 Thomas Freitag <[email protected]>
 // Copyright (C) 2009 Till Kamppeter <[email protected]>
@@ -93,9 +93,10 @@ class PSOutputDev: public OutputDev {
 public:
 
   // Open a PostScript output file, and write the prolog.
+  // pages has to be sorted in increasing order
   PSOutputDev(const char *fileName, PDFDoc *docA,
              char *psTitle,
-             int firstPage, int lastPage, PSOutMode modeA,
+             const std::vector<int> &pages, PSOutMode modeA,
              int paperWidthA = -1, int paperHeightA = -1,
               GBool noCrop = gFalse,
              GBool duplexA = gTrue,
@@ -107,10 +108,11 @@ public:
              void *customCodeCbkDataA = NULL);
 
   // Open a PSOutputDev that will write to a generic stream.
+  // pages has to be sorted in increasing order
   PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
              char *psTitle,
              PDFDoc *docA,
-             int firstPage, int lastPage, PSOutMode modeA,
+             const std::vector<int> &pages, PSOutMode modeA,
              int paperWidthA = -1, int paperHeightA = -1,
               GBool noCrop = gFalse,
              GBool duplexA = gTrue,
@@ -160,7 +162,7 @@ public:
   //----- header/trailer (used only if manualCtrl is true)
 
   // Write the document-level header.
-  void writeHeader(int firstPage, int lastPage,
+  void writeHeader(const std::vector<int> &pages,
                   PDFRectangle *mediaBox, PDFRectangle *cropBox,
                   int pageRotate, char *pstitle);
 
@@ -310,7 +312,7 @@ private:
 
   void init(PSOutputFunc outputFuncA, void *outputStreamA,
            PSFileType fileTypeA, char *pstitle, PDFDoc *doc,
-           int firstPage, int lastPage, PSOutMode modeA,
+           const std::vector<int> &pages, PSOutMode modeA,
            int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
            GBool manualCtrlA, int paperWidthA, int paperHeightA,
             GBool noCropA, GBool duplexA);
@@ -386,7 +388,7 @@ private:
   GooString *filterPSName(GooString *name);
 
   // Write the document-level setup.
-  void writeDocSetup(PDFDoc *doc, Catalog *catalog, int firstPage, int 
lastPage, GBool duplexA);
+  void writeDocSetup(PDFDoc *doc, Catalog *catalog, const std::vector<int> 
&pages, GBool duplexA);
 
   void writePSChar(char c);
   void writePS(const char *s);
diff --git a/qt4/src/poppler-ps-converter.cc b/qt4/src/poppler-ps-converter.cc
index d69b345..4b43d8e 100644
--- a/qt4/src/poppler-ps-converter.cc
+++ b/qt4/src/poppler-ps-converter.cc
@@ -1,5 +1,5 @@
 /* poppler-ps-converter.cc: qt interface to poppler
- * Copyright (C) 2007, 2009, 2010, Albert Astals Cid <[email protected]>
+ * Copyright (C) 2007, 2009, 2010, 2015, Albert Astals Cid <[email protected]>
  * Copyright (C) 2008, Pino Toscano <[email protected]>
  * Copyright (C) 2010 Hib Eris <[email protected]>
  * Copyright (C) 2011 Glad Deschrijver <[email protected]>
@@ -216,11 +216,16 @@ bool PSConverter::convert()
        if (!d->title.isEmpty()) pstitlechar = pstitle8Bit.data();
        else pstitlechar = 0;
        
+       std::vector<int> pages;
+       foreach(int page, d->pageList)
+       {
+               pages.push_back(page);
+       }
+
        PSOutputDev *psOut = new PSOutputDev(outputToQIODevice, dev,
                                             pstitlechar,
                                             d->document->doc,
-                                            1,
-                                            d->document->doc->getNumPages(),
+                                            pages,
                                             (d->opts & PrintToEPS) ? psModeEPS 
: psModePS,
                                             d->paperWidth,
                                             d->paperHeight,
diff --git a/qt5/src/poppler-ps-converter.cc b/qt5/src/poppler-ps-converter.cc
index 0e81b70..9d0a7b3 100644
--- a/qt5/src/poppler-ps-converter.cc
+++ b/qt5/src/poppler-ps-converter.cc
@@ -1,5 +1,5 @@
 /* poppler-ps-converter.cc: qt interface to poppler
- * Copyright (C) 2007, 2009, 2010, Albert Astals Cid <[email protected]>
+ * Copyright (C) 2007, 2009, 2010, 2015, Albert Astals Cid <[email protected]>
  * Copyright (C) 2008, Pino Toscano <[email protected]>
  * Copyright (C) 2010 Hib Eris <[email protected]>
  * Copyright (C) 2011 Glad Deschrijver <[email protected]>
@@ -216,11 +216,16 @@ bool PSConverter::convert()
        if (!d->title.isEmpty()) pstitlechar = pstitle8Bit.data();
        else pstitlechar = 0;
        
+       std::vector<int> pages;
+       foreach(int page, d->pageList)
+       {
+               pages.push_back(page);
+       }
+
        PSOutputDev *psOut = new PSOutputDev(outputToQIODevice, dev,
                                             pstitlechar,
                                             d->document->doc,
-                                            1,
-                                            d->document->doc->getNumPages(),
+                                            pages,
                                             (d->opts & PrintToEPS) ? psModeEPS 
: psModePS,
                                             d->paperWidth,
                                             d->paperHeight,
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index babebed..fbc3d67 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -16,7 +16,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2006 Kristian Høgsberg <[email protected]>
-// Copyright (C) 2007-2008, 2010 Albert Astals Cid <[email protected]>
+// Copyright (C) 2007-2008, 2010, 2015 Albert Astals Cid <[email protected]>
 // Copyright (C) 2009 Till Kamppeter <[email protected]>
 // Copyright (C) 2009 Sanjoy Mahajan <[email protected]>
 // Copyright (C) 2009, 2011, 2012 William Bader <[email protected]>
@@ -206,6 +206,7 @@ int main(int argc, char *argv[]) {
   GBool ok;
   char *p;
   int exitCode;
+  std::vector<int> pages;
 
   exitCode = 99;
 
@@ -400,16 +401,22 @@ int main(int argc, char *argv[]) {
     goto err2;
   }
 
+  for (int i = firstPage; i <= lastPage; ++i) {
+    pages.push_back(i);
+  }
+
   // write PostScript file
   psOut = new PSOutputDev(psFileName->getCString(), doc,
-                         NULL, firstPage, lastPage, mode,
+                         NULL, pages, mode,
                          paperWidth,
                          paperHeight,
                           noCrop,
                          duplex);
   if (psOut->isOk()) {
-    doc->displayPages(psOut, firstPage, lastPage, 72, 72,
-                     0, noCrop, !noCrop, gTrue);
+    for (int i = firstPage; i <= lastPage; ++i) {
+      doc->displayPage(psOut, i, 72, 72,
+                       0, noCrop, !noCrop, gTrue);
+    }
   } else {
     delete psOut;
     exitCode = 2;
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to