--- pdftopdf/P2PCatalog.cxx.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/P2PCatalog.cxx 2008-10-07 22:49:44.000000000 +0200 @@ -68,6 +68,11 @@ return pageTree->nup(n,box,borderFlag,layout,xpos,ypos); } +void P2PCatalog::select(const char *pageSet, const char *pageRanges) +{ + pageTree->select(pageSet,pageRanges); +} + void P2PCatalog::fit(PDFRectangle *box, double zoom) { pageTree->fit(box,zoom); --- pdftopdf/P2PCatalog.h.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/P2PCatalog.h 2008-10-07 22:46:18.000000000 +0200 @@ -48,6 +48,7 @@ virtual void output(P2POutputStream *str, int copies, GBool collate); int nup(int n, PDFRectangle *box, unsigned int borderFlag, unsigned int layout, int xpos, int ypos); + void select(const char *pageSet, const char *pageRanges); void fit(PDFRectangle *box, double zoom); void mirror(); void rotate(int orientation); --- pdftopdf/P2PDoc.cxx.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/P2PDoc.cxx 2008-10-07 22:56:02.000000000 +0200 @@ -174,6 +174,11 @@ return catalog->nup(n,box,borderFlag,layout,xpos,ypos); } +void P2PDoc::select() +{ + catalog->select(options.pageSet,options.pageRanges); +} + void P2PDoc::fit(PDFRectangle *box, double zoom) { catalog->fit(box,zoom); --- pdftopdf/P2PDoc.h.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/P2PDoc.h 2008-10-07 22:57:11.000000000 +0200 @@ -108,6 +108,7 @@ bool deviceCollate = false); int nup(int n, PDFRectangle *box, unsigned int borderFlag, unsigned int layout, int xpos, int ypos); + void select(); void fit(PDFRectangle *box, double zoom); void mirror(); void rotate(int orientation); --- pdftopdf/P2PPageTree.cxx.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/P2PPageTree.cxx 2008-10-07 23:07:40.000000000 +0200 @@ -86,18 +86,13 @@ P2PPageTree::P2PPageTree(Catalog *orgCatalogA, XRef *xrefA) { int i; - int n; xref = xrefA; numPages = orgCatalogA->getNumPages(); pages = new P2PPage *[numPages]; - for (n = 0, i = 0;i < numPages;i++) { - if (checkPageRange(i+1,P2PDoc::options.pageSet, - P2PDoc::options.pageRanges)) { - pages[n++] = new P2PPage(orgCatalogA->getPage(i+1),xref); - } + for (i = 0;i < numPages;i++) { + pages[i] = new P2PPage(orgCatalogA->getPage(i+1),xref); } - numPages = n; } void P2PPageTree::cleanPages(P2PPage **pagesA, int size) @@ -244,6 +239,24 @@ return 0; } +void P2PPageTree::select(const char *pageSet, const char *pageRanges) +{ + P2PPage **newPages; + int i,j; + + newPages = new P2PPage *[numPages]; + for (i = 0,j = 0;i < numPages;i++) { + if (checkPageRange(i+1, pageSet, pageRanges)) { + newPages[j ++] = pages[i]; + } else { + delete pages[i]; + } + } + delete pages; + pages = newPages; + numPages = j; +} + void P2PPageTree::fit(PDFRectangle *box, double zoom) { int i; --- pdftopdf/P2PPageTree.h.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/P2PPageTree.h 2008-10-07 22:46:44.000000000 +0200 @@ -49,6 +49,7 @@ virtual void output(P2POutputStream *str, int copies, GBool collate); int nup(int n, PDFRectangle *box, unsigned int borderFlag, unsigned int layout, int xpos, int ypos); + void select(const char *pageSet, const char *pageRanges); void fit(PDFRectangle *box, double zoom); void mirror(); void rotate(int orientation); --- pdftopdf/pdftopdf.cxx.orig 2008-10-04 20:26:52.000000000 +0200 +++ pdftopdf/pdftopdf.cxx 2008-10-07 22:56:10.000000000 +0200 @@ -659,6 +659,8 @@ p2pdoc->position(&box,xposition,yposition); } + p2pdoc->select(); + /* set all pages's mediaBox to the target page size */ p2pdoc->setMediaBox(&mediaBox);