diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 8fd3107..1e4e42d 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -1096,12 +1096,68 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA, paperWidthA, paperHeightA, duplexA); } +PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA, + char *psTitle, + PDFDoc *doc, + XRef *xrefA, Catalog *catalog, + int *pageList, const int pageListSize, PSOutMode modeA, + int paperWidthA, int paperHeightA, GBool duplexA, + int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, + GBool forceRasterizeA, + GBool manualCtrlA) { + underlayCbk = NULL; + underlayCbkData = NULL; + overlayCbk = NULL; + overlayCbkData = NULL; + + fontIDs = NULL; + fontFileIDs = NULL; + fontFileNames = NULL; + font8Info = NULL; + font16Enc = NULL; + imgIDs = NULL; + formIDs = NULL; + xobjStack = NULL; + embFontList = NULL; + customColors = NULL; + haveTextClip = gFalse; + haveCSPattern = gFalse; + t3String = NULL; + + forceRasterize = forceRasterizeA; + + init(outputFuncA, outputStreamA, psGeneric, psTitle, + doc, xrefA, catalog, pageList, pageListSize, modeA, + imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA, + paperWidthA, paperHeightA, duplexA); +} + void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, PSFileType fileTypeA, char *pstitle, PDFDoc *doc, XRef *xrefA, Catalog *catalog, int firstPage, int lastPage, PSOutMode modeA, int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, GBool manualCtrlA, int paperWidthA, int paperHeightA, GBool duplexA) { + + const int pageListSize = lastPage-firstPage + 1; + int *pageList = new int[pageListSize]; + for (int i = firstPage; i < pageListSize; ++i) pageList[i] = firstPage+i; + + init(outputFuncA, outputStreamA, fileTypeA, pstitle, + doc, xrefA, catalog, pageList, pageListSize, modeA, + imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA, + paperWidthA, paperHeightA, duplexA); + + delete pageList; + +} + +void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, + PSFileType fileTypeA, char *pstitle, PDFDoc *doc, XRef *xrefA, Catalog *catalog, + int *pageList, const int pageListSize, PSOutMode modeA, + int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, + GBool manualCtrlA, int paperWidthA, int paperHeightA, + GBool duplexA) { PDFRectangle *box; // initialize @@ -1122,11 +1178,11 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, imgURY = imgURYA; if (paperWidth < 0 || paperHeight < 0) { Page *page; - if ((page = doc->getPage(firstPage))) { + if ((pageListSize > 0) && ((page = doc->getPage(pageList[0])))) { paperWidth = (int)ceil(page->getMediaWidth()); paperHeight = (int)ceil(page->getMediaHeight()); } else { - error(-1, "Invalid page %d", firstPage); + error(-1, "Invalid page %d", (pageListSize > 0)?pageList[0]:0); paperWidth = 1; paperHeight = 1; } @@ -1144,9 +1200,6 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, imgURY = paperHeight; } manualCtrl = manualCtrlA; - if (mode == psModeForm) { - lastPage = firstPage; - } processColors = 0; inType3Char = gFalse; inUncoloredPattern = gFalse; @@ -1195,16 +1248,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 ((pageListSize > 0) && ((page = doc->getPage(pageList[0])))) { + writeHeader(pageListSize, page->getMediaBox(), page->getCropBox(), page->getRotate(), pstitle); } else { - error(-1, "Invalid page %d", firstPage); + error(-1, "Invalid page %d", (pageListSize > 0)?pageList[0]:0); box = new PDFRectangle(0, 0, 1, 1); - writeHeader(firstPage, lastPage, box, box, 0, pstitle); + writeHeader(pageListSize, box, box, 0, pstitle); delete box; } if (mode != psModeForm) { @@ -1215,7 +1268,7 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, writePS("%%EndProlog\n"); writePS("%%BeginSetup\n"); } - writeDocSetup(doc, catalog, firstPage, lastPage, duplexA); + writeDocSetup(doc, catalog, pageList, pageListSize, duplexA); if (mode != psModeForm) { writePS("%%EndSetup\n"); } @@ -1391,6 +1444,16 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage, } } +void PSOutputDev::writeHeader(const int pageCount, + PDFRectangle *mediaBox, PDFRectangle *cropBox, + int pageRotate, char *psTitle) { + + writeHeader(0, pageCount-1, + mediaBox, cropBox, + pageRotate, psTitle); + +} + void PSOutputDev::writeXpdfProcset() { GBool lev1, lev2, lev3, sep, nonSep; char **p; @@ -1430,7 +1493,7 @@ void PSOutputDev::writeXpdfProcset() { } void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog, - int firstPage, int lastPage, + int *pageList, const int pageListSize, GBool duplexA) { Page *page; Dict *resDict; @@ -1444,8 +1507,8 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog, } else { writePS("xpdf begin\n"); } - for (pg = firstPage; pg <= lastPage; ++pg) { - page = doc->getPage(pg); + for (int page_i = 0; page_i < pageListSize; ++page_i) { + page = doc->getPage(pageList[page_i]); if (!page) { error(-1, "Failed writing resources for page %d", pg); continue; diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h index 8112bc4..132cdb9 100644 --- a/poppler/PSOutputDev.h +++ b/poppler/PSOutputDev.h @@ -101,6 +101,18 @@ public: GBool forceRasterizeA = gFalse, GBool manualCtrlA = gFalse); + PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA, + char *psTitle, + PDFDoc *doc, + XRef *xrefA, Catalog *catalog, + int *pageList, const int pageListSize, PSOutMode modeA, + int paperWidthA = -1, int paperHeightA = -1, + GBool duplexA = gTrue, + int imgLLXA = 0, int imgLLYA = 0, + int imgURXA = 0, int imgURYA = 0, + GBool forceRasterizeA = gFalse, + GBool manualCtrlA = gFalse); + // Destructor -- writes the trailer and closes the file. virtual ~PSOutputDev(); @@ -146,6 +158,10 @@ public: PDFRectangle *mediaBox, PDFRectangle *cropBox, int pageRotate, char *pstitle); + void writeHeader(const int pageCount, + PDFRectangle *mediaBox, PDFRectangle *cropBox, + int pageRotate, char *pstitle); + // Write the Xpdf procset. void writeXpdfProcset(); @@ -293,6 +309,12 @@ private: int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, GBool manualCtrlA, int paperWidthA, int paperHeightA, GBool duplexA); + void init(PSOutputFunc outputFuncA, void *outputStreamA, + PSFileType fileTypeA, char *pstitle, PDFDoc *doc, XRef *xrefA, Catalog *catalog, + int *pageList, const int pageListSize, PSOutMode modeA, + int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, + GBool manualCtrlA, int paperWidthA, int paperHeightA, + GBool duplexA); void setupResources(Dict *resDict); void setupFonts(Dict *resDict); void setupFont(GfxFont *font, Dict *parentResDict); @@ -359,7 +381,7 @@ private: void cvtFunction(Function *func); // Write the document-level setup. - void writeDocSetup(PDFDoc *doc, Catalog *catalog, int firstPage, int lastPage, GBool duplexA); + void writeDocSetup(PDFDoc *doc, Catalog *catalog, int *pageList, const int pageListSize, GBool duplexA); void writePSChar(char c); void writePS(char *s); diff --git a/qt4/src/poppler-ps-converter.cc b/qt4/src/poppler-ps-converter.cc index 4472b0f..0d3df92 100644 --- a/qt4/src/poppler-ps-converter.cc +++ b/qt4/src/poppler-ps-converter.cc @@ -203,14 +203,22 @@ bool PSConverter::convert() char* pstitlechar; if (!d->title.isEmpty()) pstitlechar = pstitle8Bit.data(); else pstitlechar = 0; - + + const int pageListSize = d->pageList.size(); + int *pageList = new int[pageListSize]; + + for (int i = 0; i < pageListSize; ++i) + { + pageList[i] = d->pageList[i]; + } + PSOutputDev *psOut = new PSOutputDev(outputToQIODevice, dev, pstitlechar, d->document->doc, d->document->doc->getXRef(), d->document->doc->getCatalog(), - 1, - d->document->doc->getNumPages(), + pageList, + pageListSize, psModePS, d->paperWidth, d->paperHeight, @@ -220,7 +228,9 @@ bool PSConverter::convert() d->paperWidth - d->marginRight, d->paperHeight - d->marginTop, (d->opts & ForceRasterization)); - + + delete pageList; + if (d->opts & StrictMargins) { double xScale = ((double)d->paperWidth - (double)d->marginLeft - (double)d->marginRight) / (double)d->paperWidth;