From: Asbjørn Sloth Tønnesen Date: Tue, 8 Jun 2010 22:23:51 +0000 (+0000) Subject: lib/pdf: make startPage() upstream compatible X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=20f395856f21739e79eeab275beec7a3d133d568;p=swftools.git lib/pdf: make startPage() upstream compatible 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 --- diff --git a/lib/pdf/BitmapOutputDev.cc b/lib/pdf/BitmapOutputDev.cc index d54c8ea..96e0d33 100644 --- a/lib/pdf/BitmapOutputDev.cc +++ b/lib/pdf/BitmapOutputDev.cc @@ -848,12 +848,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); @@ -987,15 +999,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 19b7bc1..ddbd0cd 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; @@ -803,15 +781,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 @@ @@ -964,15 +933,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(), @@ -987,15 +947,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 @@ -1127,17 +1078,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 @@ @@ -1148,15 +1088,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 @@