Commit 877d6b20 authored by Albert Astals Cid's avatar Albert Astals Cid

* glib/poppler-page.cc:

        * poppler/PSOutputDev.cc:
        * poppler/PSOutputDev.h:
        * qt/poppler-document.cc:
        * qt4/src/poppler-document.cc:
        * qt4/src/poppler-qt4.h:
        * utils/pdftohtml.cc:
        * utils/pdftops.cc:
        Add option to force rasterizing the pages when printing them
        Add functionality to output the title field on the PS file
        Only Qt4 frontend exposes the functionality

Bringing this features from KPDF 3.5.7 to poppler
Testers welcome
Patches for other frontends more than welcome
Comments and suggestions even more than welcome :-)
parent 99053be5
2007-04-27 Albert Astals Cid <aacid@kde.org>
* glib/poppler-page.cc:
* poppler/PSOutputDev.cc:
* poppler/PSOutputDev.h:
* qt/poppler-document.cc:
* qt4/src/poppler-document.cc:
* qt4/src/poppler-qt4.h:
* utils/pdftohtml.cc:
* utils/pdftops.cc:
Add option to force rasterizing the pages when printing them
Add functionality to output the title field on the PS file
Only Qt4 frontend exposes the functionality
2007-04-26 Albert Astals Cid <aacid@kde.org>
* goo/Makefile.am: Remove duplicate gmem.h
......
......@@ -789,10 +789,11 @@ poppler_page_render_to_ps (PopplerPage *page,
ps_file->out = new PSOutputDev (ps_file->filename,
ps_file->document->doc->getXRef(),
ps_file->document->doc->getCatalog(),
NULL,
ps_file->first_page, ps_file->last_page,
psModePS, (int)ps_file->paper_width,
(int)ps_file->paper_height, ps_file->duplex,
0, 0, 0, 0, gFalse);
0, 0, 0, 0, gFalse, gFalse);
ps_file->document->doc->displayPage (ps_file->out, page->index + 1, 72.0, 72.0,
......
......@@ -943,9 +943,11 @@ static void outputToFile(void *stream, char *data, int len) {
}
PSOutputDev::PSOutputDev(const char *fileName, XRef *xrefA, Catalog *catalog,
char *psTitle,
int firstPage, int lastPage, PSOutMode modeA,
int paperWidthA, int paperHeightA, GBool duplexA,
int paperWidthA, int paperHeightA, GBool duplexA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
GBool forceRasterizeA,
GBool manualCtrlA) {
FILE *f;
PSFileType fileTypeA;
......@@ -968,6 +970,8 @@ PSOutputDev::PSOutputDev(const char *fileName, XRef *xrefA, Catalog *catalog,
haveTextClip = gFalse;
t3String = NULL;
forceRasterize = forceRasterizeA;
// open file or pipe
if (!strcmp(fileName, "-")) {
fileTypeA = psStdout;
......@@ -997,17 +1001,19 @@ PSOutputDev::PSOutputDev(const char *fileName, XRef *xrefA, Catalog *catalog,
}
}
init(outputToFile, f, fileTypeA,
init(outputToFile, f, fileTypeA, psTitle,
xrefA, catalog, firstPage, lastPage, modeA,
imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA,
paperWidthA, paperHeightA, duplexA);
}
PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
char *psTitle,
XRef *xrefA, Catalog *catalog,
int firstPage, int lastPage, PSOutMode modeA,
int paperWidthA, int paperHeightA, GBool duplexA,
int paperWidthA, int paperHeightA, GBool duplexA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
GBool forceRasterizeA,
GBool manualCtrlA) {
underlayCbk = NULL;
underlayCbkData = NULL;
......@@ -1027,18 +1033,20 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
haveTextClip = gFalse;
t3String = NULL;
init(outputFuncA, outputStreamA, psGeneric,
forceRasterize = forceRasterizeA;
init(outputFuncA, outputStreamA, psGeneric, psTitle,
xrefA, catalog, firstPage, lastPage, modeA,
imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA,
paperWidthA, paperHeightA, duplexA);
}
void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
PSFileType fileTypeA, char *pstitle, 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) {
GBool duplexA) {
Page *page;
PDFRectangle *box;
......@@ -1132,10 +1140,11 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
writeHeader(firstPage, lastPage,
catalog->getPage(firstPage)->getMediaBox(),
catalog->getPage(firstPage)->getCropBox(),
catalog->getPage(firstPage)->getRotate());
catalog->getPage(firstPage)->getRotate(),
pstitle);
} else {
box = new PDFRectangle(0, 0, 1, 1);
writeHeader(firstPage, lastPage, box, box, 0);
writeHeader(firstPage, lastPage, box, box, 0, pstitle);
delete box;
}
if (mode != psModeForm) {
......@@ -1231,7 +1240,7 @@ PSOutputDev::~PSOutputDev() {
void PSOutputDev::writeHeader(int firstPage, int lastPage,
PDFRectangle *mediaBox, PDFRectangle *cropBox,
int pageRotate) {
int pageRotate, char *psTitle) {
double x1, y1, x2, y2;
Object info, obj1;
......@@ -1253,6 +1262,9 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage,
}
obj1.free();
info.free();
if(psTitle) {
writePSFmt("%%Title: {0:s}\n", psTitle);
}
writePSFmt("%%LanguageLevel: {0:d}\n",
(level == psLevel1 || level == psLevel1Sep) ? 1 :
(level == psLevel2 || level == psLevel2Sep) ? 2 : 3);
......@@ -1545,6 +1557,8 @@ void PSOutputDev::setupFonts(Dict *resDict) {
GfxFont *font;
int i;
if (forceRasterize) return;
gfxFontDict = NULL;
resDict->lookupNF("Font", &obj1);
if (obj1.isRef()) {
......@@ -2849,12 +2863,16 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
double m0, m1, m2, m3, m4, m5;
int c, w, h, x, y, comp, i;
scan = new PreScanOutputDev();
page->displaySlice(scan, 72, 72, rotateA, useMediaBox, crop,
sliceX, sliceY, sliceW, sliceH,
printing, catalog, abortCheckCbk, abortCheckCbkData);
rasterize = scan->usesTransparency();
delete scan;
if (!forceRasterize) {
scan = new PreScanOutputDev();
page->displaySlice(scan, 72, 72, rotateA, useMediaBox, crop,
sliceX, sliceY, sliceW, sliceH,
printing, catalog, abortCheckCbk, abortCheckCbkData);
rasterize = scan->usesTransparency();
delete scan;
} else {
rasterize = gTrue;
}
if (!rasterize) {
return gTrue;
}
......
......@@ -53,21 +53,25 @@ public:
// Open a PostScript output file, and write the prolog.
PSOutputDev(const char *fileName, XRef *xrefA, Catalog *catalog,
char *psTitle,
int firstPage, int lastPage, PSOutMode modeA,
int paperWidthA = -1, int paperHeightA = -1,
GBool duplexA = gTrue,
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);
// Open a PSOutputDev that will write to a generic stream.
PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
char *psTitle,
XRef *xrefA, Catalog *catalog,
int firstPage, int lastPage, PSOutMode modeA,
int paperWidthA = -1, int paperHeightA = -1,
GBool duplexA = gTrue,
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.
......@@ -109,7 +113,7 @@ public:
// Write the document-level header.
void writeHeader(int firstPage, int lastPage,
PDFRectangle *mediaBox, PDFRectangle *cropBox,
int pageRotate);
int pageRotate, char *pstitle);
// Write the Xpdf procset.
void writeXpdfProcset();
......@@ -246,7 +250,7 @@ public:
private:
void init(PSOutputFunc outputFuncA, void *outputStreamA,
PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
PSFileType fileTypeA, char *pstitle, XRef *xrefA, Catalog *catalog,
int firstPage, int lastPage, PSOutMode modeA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
GBool manualCtrlA, int paperWidthA, int paperHeightA,
......@@ -385,6 +389,7 @@ private:
t3LLX, t3LLY, t3URX, t3URY;
GBool t3Cacheable; // cleared if char is not cacheable
GBool t3NeedsRestore; // set if a 'q' operator was issued
GBool forceRasterize; // forces the page to be rasterized into a image before printing
#if OPI_SUPPORT
int opi13Nest; // nesting level of OPI 1.3 objects
......
......@@ -317,7 +317,7 @@ bool Document::print(const QString &fileName, QValueList<int> pageList, double h
bool Document::print(const QString &file, QValueList<int> pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight)
{
PSOutputDev *psOut = new PSOutputDev(file.latin1(), data->doc.getXRef(), data->doc.getCatalog(), 1, data->doc.getNumPages(), psModePS, paperWidth, paperHeight);
PSOutputDev *psOut = new PSOutputDev(file.latin1(), data->doc.getXRef(), data->doc.getCatalog(), NULL, 1, data->doc.getNumPages(), psModePS, paperWidth, paperHeight);
if (psOut->isOk()) {
QValueList<int>::iterator it;
......
......@@ -414,9 +414,14 @@ namespace Poppler {
return ld;
}
bool Document::print(const QString &file, const QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, bool strictMargins)
bool Document::print(const QString &file, const QString &title, const QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, bool strictMargins, bool forceRasterize)
{
PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), m_doc->doc->getXRef(), m_doc->doc->getCatalog(), 1, m_doc->doc->getNumPages(), psModePS, paperWidth, paperHeight, gFalse, marginRight, marginBottom, paperWidth - marginLeft, paperHeight - marginTop);
QByteArray pstitle8Bit = title.toLocal8Bit();
char* pstitlechar;
if (!title.isEmpty()) pstitlechar = pstitle8Bit.data();
else pstitlechar = 0;
PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), m_doc->doc->getXRef(), m_doc->doc->getCatalog(), pstitlechar, 1, m_doc->doc->getNumPages(), psModePS, paperWidth, paperHeight, gFalse, marginRight, marginBottom, paperWidth - marginLeft, paperHeight - marginTop, forceRasterize);
if (strictMargins)
{
......
......@@ -729,7 +729,7 @@ width = dummy.width();
height = dummy.height();
\endcode
*/
bool print(const QString &fileName, const QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, bool strictMargins);
bool print(const QString &fileName, const QString &title, const QList<int> &pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight, int marginRight, int marginBottom, int marginLeft, int marginTop, bool strictMargins, bool forceRasterize);
/**
Sets the paper color
......
......@@ -318,7 +318,7 @@ int main(int argc, char *argv[]) {
// XXX
// globalParams->setPSNoText(gTrue);
psOut = new PSOutputDev(psFileName->getCString(), doc->getXRef(),
doc->getCatalog(), firstPage, lastPage, psModePS, w, h);
doc->getCatalog(), NULL, firstPage, lastPage, psModePS, w, h);
doc->displayPages(psOut, firstPage, lastPage, 72, 72, 0,
gTrue, gFalse, gFalse);
delete psOut;
......
......@@ -319,7 +319,7 @@ int main(int argc, char *argv[]) {
// write PostScript file
psOut = new PSOutputDev(psFileName->getCString(), doc->getXRef(),
doc->getCatalog(), firstPage, lastPage, mode,
doc->getCatalog(), NULL, firstPage, lastPage, mode,
paperWidth,
paperHeight,
duplex);
......
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