-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello Albert,
Am 31.10.2014 um 00:01 schrieb Albert Astals Cid:
> Hi guys, i made a patch for PSOutputDev and i think it's good, but
> extra set of eyes are never a bad thing.
>
> https://bugs.freedesktop.org/attachment.cgi?id=108708
>
> Basically it's so that you don't have to pass firstPage-lastPage to
> PSOutputDev and can simply pass an arbitrary set of pages.
I had a look and I think it is correct. However, I did only test it
using "pdftops" and not using the Glib or Qt code paths.
As a small style improvement, I would suggest turning "pgi" into a
"size_t" to get rid of the cast. I would also replace "pg" of type
"int" within "writeDocSetup" by a "pgi" of type "size_t" to remove the
cast and any chance of possible confusion, i.e. someone forgetting
that "pg" is not the page number anymore, but an index to the page vector.
I just noticed this had already happened with the error message, so
I'll attach a slightly modified version of your patch.
Best regards, Adam.
> Thanks, Albert
>
> P.S: Yes i know i have lots of patches in the queue to review
> P.S.2: I was planning to release 0.28 today but maybe tomorrow or
> over the weekend, i'd like to at least get
> https://bugs.freedesktop.org/show_bug.cgi?id=81724 and
> https://bugs.freedesktop.org/show_bug.cgi?id=85234 in.
>
> _______________________________________________ poppler mailing
> list [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQEcBAEBAgAGBQJUU0YuAAoJEPSSjE3STU34E3EIAMa7FhJCJwWFnIKtgEFg9LAZ
Oail139anhhyIZ/Mf5sSE1nAjEB0HGbN2nWVpwyM2VvgPy1eQRcYBuaEjpTY3gJG
hqvTj6d/K2+84tcWFitj0mnRPUfXhCUkei5c+heXzIZXAgGtx6FD/Sc0AsZI9Wu0
LHpP7BruXCqoMovvEWMdgn4ZV2xVqihId88GFbG6mob93dHLTQfYGloqgSwKvE9e
pRKOP8okdHAIycByi0wvuhmlALIXDqVQhsKiF+D5JE+dwiqs0g3rxYPXQapZQa+4
i/D2S9/aMPhiYVdybqOYtKjUslR2wTWj7BbVk9+BpAVbCeLIk+xMI3adHn4hdmE=
=FjuM
-----END PGP SIGNATURE-----
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..f090e1d 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -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..3493fe3 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -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..f9d8538 100644
--- a/qt4/src/poppler-ps-converter.cc
+++ b/qt4/src/poppler-ps-converter.cc
@@ -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..41f85a1 100644
--- a/qt5/src/poppler-ps-converter.cc
+++ b/qt5/src/poppler-ps-converter.cc
@@ -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..5104c31 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -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