Commit 9caf7525 authored by Albert Astals Cid's avatar Albert Astals Cid

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?"
parent 173f182f
......@@ -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,
......
......@@ -15,7 +15,7 @@
//
// Copyright (C) 2005 Martin Kretzschmar <martink@gnome.org>
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006-2009, 2011-2013 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006-2009, 2011-2013, 2015 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2007, 2008 Brad Hards <bradh@kde.org>
// Copyright (C) 2008, 2009 Koji Otani <sho@bbr.jp>
......@@ -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);
......
......@@ -15,7 +15,7 @@
//
// Copyright (C) 2005 Martin Kretzschmar <martink@gnome.org>
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006-2008, 2012, 2013 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006-2008, 2012, 2013, 2015 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2007 Brad Hards <bradh@kde.org>
// Copyright (C) 2009-2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2009 Till Kamppeter <till.kamppeter@gmail.com>
......@@ -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);
......
/* poppler-ps-converter.cc: qt interface to poppler
* Copyright (C) 2007, 2009, 2010, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007, 2009, 2010, 2015, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2008, Pino Toscano <pino@kde.org>
* Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
* Copyright (C) 2011 Glad Deschrijver <glad.deschrijver@gmail.com>
......@@ -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,
......
/* poppler-ps-converter.cc: qt interface to poppler
* Copyright (C) 2007, 2009, 2010, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2007, 2009, 2010, 2015, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2008, Pino Toscano <pino@kde.org>
* Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
* Copyright (C) 2011 Glad Deschrijver <glad.deschrijver@gmail.com>
......@@ -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,
......
......@@ -16,7 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2007-2008, 2010, 2015 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Till Kamppeter <till.kamppeter@gmail.com>
// Copyright (C) 2009 Sanjoy Mahajan <sanjoy@mit.edu>
// Copyright (C) 2009, 2011, 2012 William Bader <williambader@hotmail.com>
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment