lib/pdf: make startPage() upstream compatible
authorAsbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>
Tue, 8 Jun 2010 22:23:51 +0000 (22:23 +0000)
committerMatthias Kramm <kramm@quiss.org>
Thu, 10 Jun 2010 21:27:19 +0000 (14:27 -0700)
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 <asbjorn@asbjorn.biz>

14 files changed:
lib/pdf/BitmapOutputDev.cc
lib/pdf/BitmapOutputDev.h
lib/pdf/CommonOutputDev.h
lib/pdf/DummyOutputDev.cc
lib/pdf/DummyOutputDev.h
lib/pdf/FullBitmapOutputDev.cc
lib/pdf/FullBitmapOutputDev.h
lib/pdf/GFXOutputDev.cc
lib/pdf/GFXOutputDev.h
lib/pdf/InfoOutputDev.cc
lib/pdf/InfoOutputDev.h
lib/pdf/XMLOutputDev.cc
lib/pdf/XMLOutputDev.h
lib/pdf/xpdf-changes.patch

index a858765..6b16993 100644 (file)
@@ -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(x2<x1) {double x3=x1;x1=x2;x2=x3;}
     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
     
@@ -872,12 +884,12 @@ void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, do
     this->width = (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);
index 91e110a..c5c9375 100644 (file)
@@ -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();
 
index 476df3b..31b70af 100644 (file)
@@ -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__
index 76a5a49..a89b5c7 100644 (file)
@@ -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()
index cb8d7ac..ca831a8 100644 (file)
@@ -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);
index 9cd2cc1..6b80802 100644 (file)
@@ -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(x2<x1) {double x3=x1;x1=x2;x2=x3;}
     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
     
@@ -214,8 +227,8 @@ void FullBitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1
     this->height = (int)(y2-y1);
 
     msg("<debug> 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()
index 4e987a0..ab49f5c 100644 (file)
@@ -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);
index 13f7087..ef2dde3 100644 (file)
@@ -1626,7 +1626,7 @@ void GFXOutputDev::endType3Char(GfxState *state)
     msg("<debug> 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(x2<x1) {double x3=x1;x1=x2;x2=x3;}
     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
index f06dd21..4c9d75b 100644 (file)
@@ -73,7 +73,7 @@ public:
   virtual void setParameter(const char*key, const char*value);
   
   // Start a page.
-  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();
 
   //----- get info about output device
index 8fb751a..aa253be 100644 (file)
@@ -298,11 +298,23 @@ GBool InfoOutputDev::useDrawChar() {return gTrue;}
 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
 
-void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
+GBool InfoOutputDev::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->page = 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(x2<x1) {double x3=x1;x1=x2;x2=x3;}
     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
     this->x1 = (int)x1;
index 4198b7d..ec3cdb1 100644 (file)
@@ -24,6 +24,7 @@
 #include "GfxFont.h"
 #include "OutputDev.h"
 #include "SplashOutputDev.h"
+#include "Page.h"
 #ifdef HAVE_POPPLER
 #include <splash/SplashTypes.h>
 #include <splash/SplashPath.h>
@@ -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);
index 9238873..d04e2bd 100644 (file)
@@ -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, "<page nr=\"%d\" width=\"%.0f\" height=\"%.0f\">\n", pageNum,
        state->getPageWidth(), state->getPageHeight());
 }
index b06c231..4144622 100644 (file)
@@ -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:
index 625b971..2cdaf30 100644 (file)
      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 @@
      }
 --- 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;
  
  
  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 @@
  #include <math.h>
  #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(),
        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
  };
  
  //------------------------------------------------------------------------
---- 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 @@
  };
  
  //------------------------------------------------------------------------
-@@ -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 @@