From 3583bb178b85790e8459da31ef69f852e3d8c05f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Tue, 8 Jun 2010 22:23:51 +0000 Subject: [PATCH] lib/pdf: make startPage() upstream compatible MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Make startPage() obtain the needed cropBox through the Page instance, supplied by the always preseeding checkPageSlice() call. This patch makes startPage() compatible with both upstream xpdf and poppler. Signed-off-by: Asbjørn Sloth Tønnesen --- lib/pdf/BitmapOutputDev.cc | 39 ++++++++++++----------- lib/pdf/BitmapOutputDev.h | 6 ++-- lib/pdf/CommonOutputDev.h | 16 ++++++++++ lib/pdf/DummyOutputDev.cc | 4 +-- lib/pdf/DummyOutputDev.h | 2 +- lib/pdf/FullBitmapOutputDev.cc | 23 +++++++++++--- lib/pdf/FullBitmapOutputDev.h | 6 ++-- lib/pdf/GFXOutputDev.cc | 7 ++-- lib/pdf/GFXOutputDev.h | 2 +- lib/pdf/InfoOutputDev.cc | 18 +++++++++-- lib/pdf/InfoOutputDev.h | 10 +++++- lib/pdf/XMLOutputDev.cc | 4 +-- lib/pdf/XMLOutputDev.h | 2 +- lib/pdf/xpdf-changes.patch | 69 ---------------------------------------- 14 files changed, 96 insertions(+), 112 deletions(-) diff --git a/lib/pdf/BitmapOutputDev.cc b/lib/pdf/BitmapOutputDev.cc index a858765..6b16993 100644 --- a/lib/pdf/BitmapOutputDev.cc +++ b/lib/pdf/BitmapOutputDev.cc @@ -851,12 +851,24 @@ GBool BitmapOutputDev::intersection(SplashBitmap*boolpoly, SplashBitmap*booltext } } +GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI, + int rotate, GBool useMediaBox, GBool crop, + int sliceX, int sliceY, int sliceW, int sliceH, + GBool printing, Catalog *catalog, + GBool (*abortCheckCbk)(void *data), + void *abortCheckCbkData) +{ + this->setPage(page); + gfxdev->setPage(page); + return gTrue; +} -void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) +void BitmapOutputDev::startPage(int pageNum, GfxState *state) { + PDFRectangle *r = this->page->getCropBox(); double x1,y1,x2,y2; - state->transform(crop_x1,crop_y1,&x1,&y1); - state->transform(crop_x2,crop_y2,&x2,&y2); + state->transform(r->x1,r->y1,&x1,&y1); + state->transform(r->x2,r->y2,&x2,&y2); if(x2width = (int)(x2-x1); this->height = (int)(y2-y1); - rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); - boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); - booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); - clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); - clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); - gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); + rgbdev->startPage(pageNum, state); + boolpolydev->startPage(pageNum, state); + booltextdev->startPage(pageNum, state); + clip0dev->startPage(pageNum, state); + clip1dev->startPage(pageNum, state); + gfxdev->startPage(pageNum, state); boolpolybitmap = boolpolydev->getBitmap(); stalepolybitmap = new SplashBitmap(boolpolybitmap->getWidth(), boolpolybitmap->getHeight(), 1, boolpolybitmap->getMode(), 0); @@ -990,15 +1002,6 @@ GBool BitmapOutputDev::needNonText() clip1dev->needNonText(); return rgbdev->needNonText(); } -/*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI, - int rotate, GBool useMediaBox, GBool crop, - int sliceX, int sliceY, int sliceW, int sliceH, - GBool printing, Catalog *catalog, - GBool (*abortCheckCbk)(void *data), - void *abortCheckCbkData) -{ - return gTrue; -}*/ void BitmapOutputDev::setDefaultCTM(double *ctm) { boolpolydev->setDefaultCTM(ctm); diff --git a/lib/pdf/BitmapOutputDev.h b/lib/pdf/BitmapOutputDev.h index 91e110a..c5c9375 100644 --- a/lib/pdf/BitmapOutputDev.h +++ b/lib/pdf/BitmapOutputDev.h @@ -65,14 +65,14 @@ public: virtual GBool interpretType3Chars(); virtual GBool needNonText(); virtual void setDefaultCTM(double *ctm); -/* virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI, + virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI, int rotate, GBool useMediaBox, GBool crop, int sliceX, int sliceY, int sliceW, int sliceH, GBool printing, Catalog *catalog, GBool (*abortCheckCbk)(void *data) = NULL, - void *abortCheckCbkData = NULL);*/ + void *abortCheckCbkData = NULL); - virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2); + virtual void startPage(int pageNum, GfxState *state); virtual void endPage(); virtual void finishPage(); diff --git a/lib/pdf/CommonOutputDev.h b/lib/pdf/CommonOutputDev.h index 476df3b..31b70af 100644 --- a/lib/pdf/CommonOutputDev.h +++ b/lib/pdf/CommonOutputDev.h @@ -21,6 +21,7 @@ #define __commonoutputdev_h__ #include "OutputDev.h" +#include "../gfxdevice.h" #define RENDER_FILL 0 #define RENDER_STROKE 1 @@ -37,6 +38,21 @@ class CommonOutputDev: public OutputDev virtual void setParameter(const char*key, const char*value) = 0; virtual void setPageMap(int*pagemap, int pagemap_len) = 0; + virtual void setPage(Page *page) { this->page = page; } virtual void finishPage() {}; + + virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI, + int rotate, GBool useMediaBox, GBool crop, + int sliceX, int sliceY, int sliceW, int sliceH, + GBool printing, Catalog *catalog, + GBool (*abortCheckCbk)(void *data) = NULL, + void *abortCheckCbkData = NULL) + { + this->setPage(page); + return gTrue; + } + + protected: + Page *page; }; #endif //__deviceinterface_h__ diff --git a/lib/pdf/DummyOutputDev.cc b/lib/pdf/DummyOutputDev.cc index 76a5a49..a89b5c7 100644 --- a/lib/pdf/DummyOutputDev.cc +++ b/lib/pdf/DummyOutputDev.cc @@ -39,9 +39,9 @@ DummyOutputDev::~DummyOutputDev() delete this->rgbdev;this->rgbdev= 0; } } -void DummyOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) +void DummyOutputDev::startPage(int pageNum, GfxState *state) { - rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); + rgbdev->startPage(pageNum, state); } void DummyOutputDev::endPage() diff --git a/lib/pdf/DummyOutputDev.h b/lib/pdf/DummyOutputDev.h index cb8d7ac..ca831a8 100644 --- a/lib/pdf/DummyOutputDev.h +++ b/lib/pdf/DummyOutputDev.h @@ -53,7 +53,7 @@ public: GBool (*abortCheckCbk)(void *data) = NULL, void *abortCheckCbkData = NULL);*/ - virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2); + virtual void startPage(int pageNum, GfxState *state); virtual void endPage(); virtual void saveState(GfxState *state); diff --git a/lib/pdf/FullBitmapOutputDev.cc b/lib/pdf/FullBitmapOutputDev.cc index 9cd2cc1..6b80802 100644 --- a/lib/pdf/FullBitmapOutputDev.cc +++ b/lib/pdf/FullBitmapOutputDev.cc @@ -193,11 +193,24 @@ void FullBitmapOutputDev::flushBitmap() free(img->data);img->data=0;free(img);img=0; } -void FullBitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) +GBool FullBitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI, + int rotate, GBool useMediaBox, GBool crop, + int sliceX, int sliceY, int sliceW, int sliceH, + GBool printing, Catalog *catalog, + GBool (*abortCheckCbk)(void *data), + void *abortCheckCbkData) +{ + this->setPage(page); + gfxdev->setPage(page); + return gTrue; +} + +void FullBitmapOutputDev::startPage(int pageNum, GfxState *state) { double x1,y1,x2,y2; - state->transform(crop_x1,crop_y1,&x1,&y1); - state->transform(crop_x2,crop_y2,&x2,&y2); + PDFRectangle *r = page->getCropBox(); + state->transform(r->x1,r->y1,&x1,&y1); + state->transform(r->x2,r->y2,&x2,&y2); if(x2height = (int)(y2-y1); msg(" startPage"); - rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); - gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2); + rgbdev->startPage(pageNum, state); + gfxdev->startPage(pageNum, state); } void FullBitmapOutputDev::endPage() diff --git a/lib/pdf/FullBitmapOutputDev.h b/lib/pdf/FullBitmapOutputDev.h index 4e987a0..ab49f5c 100644 --- a/lib/pdf/FullBitmapOutputDev.h +++ b/lib/pdf/FullBitmapOutputDev.h @@ -55,14 +55,14 @@ public: virtual GBool interpretType3Chars(); virtual GBool needNonText(); virtual void setDefaultCTM(double *ctm); -/* virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI, + virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI, int rotate, GBool useMediaBox, GBool crop, int sliceX, int sliceY, int sliceW, int sliceH, GBool printing, Catalog *catalog, GBool (*abortCheckCbk)(void *data) = NULL, - void *abortCheckCbkData = NULL);*/ + void *abortCheckCbkData = NULL); - virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2); + virtual void startPage(int pageNum, GfxState *state); virtual void endPage(); virtual void saveState(GfxState *state); diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index 13f7087..ef2dde3 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -1626,7 +1626,7 @@ void GFXOutputDev::endType3Char(GfxState *state) msg(" endType3Char"); } -void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) +void GFXOutputDev::startPage(int pageNum, GfxState *state) { this->currentpage = pageNum; double x1,y1,x2,y2; @@ -1635,6 +1635,7 @@ void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl gfxcolor_t black = {255,0,0,0}; laststate = state; gfxline_t clippath[5]; + PDFRectangle *r = this->page->getCropBox(); /* state->transform(state->getX1(),state->getY1(),&x1,&y1); state->transform(state->getX2(),state->getY2(),&x2,&y2); @@ -1645,8 +1646,8 @@ void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl y1 = crop_y1; x2 = crop_x2; y2 = crop_y2;*/ - state->transform(crop_x1,crop_y1,&x1,&y1); //x1 += user_movex; y1 += user_movey; - state->transform(crop_x2,crop_y2,&x2,&y2); //x2 += user_movex; y2 += user_movey; + state->transform(r->x1,r->y1,&x1,&y1); //x1 += user_movex; y1 += user_movey; + state->transform(r->x2,r->y2,&x2,&y2); //x2 += user_movex; y2 += user_movey; if(x2page = page; + return gTrue; +} + +void InfoOutputDev::startPage(int pageNum, GfxState *state) +{ + PDFRectangle *r = this->page->getCropBox(); double x1,y1,x2,y2; - state->transform(crop_x1,crop_y1,&x1,&y1); - state->transform(crop_x2,crop_y2,&x2,&y2); + state->transform(r->x1,r->y1,&x1,&y1); + state->transform(r->x2,r->y2,&x2,&y2); if(x2x1 = (int)x1; diff --git a/lib/pdf/InfoOutputDev.h b/lib/pdf/InfoOutputDev.h index 4198b7d..ec3cdb1 100644 --- a/lib/pdf/InfoOutputDev.h +++ b/lib/pdf/InfoOutputDev.h @@ -24,6 +24,7 @@ #include "GfxFont.h" #include "OutputDev.h" #include "SplashOutputDev.h" +#include "Page.h" #ifdef HAVE_POPPLER #include #include @@ -99,6 +100,7 @@ class InfoOutputDev: public OutputDev FontInfo* currentfont; GlyphInfo* currentglyph; SplashOutputDev*splash; + Page *page; public: int x1,y1,x2,y2; @@ -117,7 +119,13 @@ class InfoOutputDev: public OutputDev virtual GBool upsideDown(); virtual GBool useDrawChar(); virtual GBool interpretType3Chars(); - virtual void startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2); + virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI, + int rotate, GBool useMediaBox, GBool crop, + int sliceX, int sliceY, int sliceW, int sliceH, + GBool printing, Catalog *catalog, + GBool (*abortCheckCbk)(void *data) = NULL, + void *abortCheckCbkData = NULL); + virtual void startPage(int pageNum, GfxState *state); virtual void endPage(); virtual void drawLink(Link *link, Catalog *catalog); virtual double getMaximumFontSize(char*id); diff --git a/lib/pdf/XMLOutputDev.cc b/lib/pdf/XMLOutputDev.cc index 9238873..d04e2bd 100644 --- a/lib/pdf/XMLOutputDev.cc +++ b/lib/pdf/XMLOutputDev.cc @@ -41,9 +41,9 @@ XMLOutputDev::~XMLOutputDev() fclose(out); } -void XMLOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) +void XMLOutputDev::startPage(int pageNum, GfxState *state) { - TextOutputDev::startPage(pageNum, state, x1, y1, x2, y2); + TextOutputDev::startPage(pageNum, state); fprintf(out, "\n", pageNum, state->getPageWidth(), state->getPageHeight()); } diff --git a/lib/pdf/XMLOutputDev.h b/lib/pdf/XMLOutputDev.h index b06c231..4144622 100644 --- a/lib/pdf/XMLOutputDev.h +++ b/lib/pdf/XMLOutputDev.h @@ -26,7 +26,7 @@ class XMLOutputDev: public TextOutputDev { public: XMLOutputDev(char*filename); - virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2); + virtual void startPage(int pageNum, GfxState *state); virtual void endPage(); virtual ~XMLOutputDev(); private: diff --git a/lib/pdf/xpdf-changes.patch b/lib/pdf/xpdf-changes.patch index 625b971..2cdaf30 100644 --- a/lib/pdf/xpdf-changes.patch +++ b/lib/pdf/xpdf-changes.patch @@ -85,15 +85,6 @@ for (i = oldLen; i < mapLen; ++i) { map[i] = 0; } ---- xpdf/CoreOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700 -+++ xpdf/CoreOutputDev.cc 2010-05-18 11:22:18.000000000 -0700 -@@ -57,5 +57,5 @@ - - void CoreOutputDev::clear() { - startDoc(NULL); -- startPage(0, NULL); -+ startPage(0, NULL, 0,0,0,0); - } --- xpdf/Decrypt.cc.orig 2010-05-18 11:22:18.000000000 -0700 +++ xpdf/Decrypt.cc 2010-05-18 11:22:18.000000000 -0700 @@ -596,6 +596,7 @@ @@ -106,19 +97,6 @@ } --- xpdf/Gfx.cc.orig 2010-05-18 11:22:18.000000000 -0700 +++ xpdf/Gfx.cc 2010-05-18 11:22:18.000000000 -0700 -@@ -454,7 +454,11 @@ - fontChanged = gFalse; - clip = clipNone; - ignoreUndef = 0; -- out->startPage(pageNum, state); -+ if(cropBox) { -+ out->startPage(pageNum, state, cropBox->x1,cropBox->y1,cropBox->x2,cropBox->y2); -+ } else { -+ out->startPage(pageNum, state, 0,0,0,0); -+ } - out->setDefaultCTM(state->getCTM()); - out->updateAll(state); - for (i = 0; i < 6; ++i) { @@ -465,6 +469,7 @@ abortCheckCbkData = abortCheckCbkDataA; @@ -812,15 +790,6 @@ class GString; class GfxState; -@@ -94,7 +95,7 @@ - { return gTrue; } - - // Start a page. -- virtual void startPage(int pageNum, GfxState *state) {} -+ virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {} - - // End a page. - virtual void endPage() {} --- xpdf/SplashFTFont.cc.orig 2010-05-18 11:22:18.000000000 -0700 +++ xpdf/SplashFTFont.cc 2010-05-18 11:22:18.000000000 -0700 @@ -46,6 +46,7 @@ @@ -973,15 +942,6 @@ #include #include "gfile.h" #include "GlobalParams.h" -@@ -702,7 +703,7 @@ - nT3Fonts = 0; - } - --void SplashOutputDev::startPage(int pageNum, GfxState *state) { -+void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) { - int w, h; - double *ctm; - SplashCoord mat[6]; @@ -2646,9 +2647,9 @@ softMask = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(), @@ -996,15 +956,6 @@ tBitmap->getPixel(x, y, color); --- xpdf/SplashOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700 +++ xpdf/SplashOutputDev.h 2010-05-18 11:22:18.000000000 -0700 -@@ -70,7 +70,7 @@ - //----- initialization and control - - // Start a page. -- virtual void startPage(int pageNum, GfxState *state); -+ virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2); - - // End a page. - virtual void endPage(); @@ -196,6 +196,9 @@ virtual void setVectorAntialias(GBool vaa); #endif @@ -1136,17 +1087,6 @@ }; //------------------------------------------------------------------------ ---- xpdf/TextOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700 -+++ xpdf/TextOutputDev.cc 2010-05-18 11:22:18.000000000 -0700 -@@ -3877,7 +3877,7 @@ - } - } - --void TextOutputDev::startPage(int pageNum, GfxState *state) { -+void TextOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) { - text->startPage(state); - } - --- xpdf/TextOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700 +++ xpdf/TextOutputDev.h 2010-05-18 11:22:18.000000000 -0700 @@ -170,6 +170,7 @@ @@ -1157,15 +1097,6 @@ }; //------------------------------------------------------------------------ -@@ -578,7 +579,7 @@ - //----- initialization and control - - // Start a page. -- virtual void startPage(int pageNum, GfxState *state); -+ virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2); - - // End a page. - virtual void endPage(); --- xpdf/gfile.cc.orig 2010-05-18 11:22:18.000000000 -0700 +++ xpdf/gfile.cc 2010-05-18 11:22:18.000000000 -0700 @@ -439,6 +439,52 @@ -- 1.7.10.4