added getVectorAntialias, which is necessary so that setVectorAntialias will be called
[swftools.git] / lib / pdf / BitmapOutputDev.cc
index 6849eee..0b49c2c 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <memory.h>
+#include "config.h"
 #include "BitmapOutputDev.h"
 #include "GFXOutputDev.h"
 #include "SplashBitmap.h"
@@ -27,7 +28,7 @@
 #include "../log.h"
 
 static SplashColor splash_white = {255,255,255};
-static SplashColor splash_black = {255,255,255};
+static SplashColor splash_black = {0,0,0};
     
 ClipState::ClipState()
 {
@@ -78,6 +79,14 @@ BitmapOutputDev::~BitmapOutputDev()
 
 }
 
+GBool BitmapOutputDev::getVectorAntialias()
+{
+    return this->rgbdev->getVectorAntialias();
+}
+void BitmapOutputDev::setVectorAntialias(GBool vaa)
+{
+    this->rgbdev->setVectorAntialias(vaa);
+}
 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
 {
     this->dev = dev;
@@ -147,6 +156,7 @@ void BitmapOutputDev::flush()
 {
     int width = rgbdev->getBitmapWidth();
     int height = rgbdev->getBitmapHeight();
+    
     SplashColorPtr rgb = rgbdev->getBitmap()->getDataPtr();
     Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
 
@@ -184,9 +194,12 @@ void BitmapOutputDev::flush()
        gfxcolor_t*out = &img->data[y*rangex];
        Guchar*ain = &alpha[(y+ymin)*width+xmin];
        for(x=0;x<rangex;x++) {
-           out[x].r = in[x*3+0];
-           out[x].g = in[x*3+1];
-           out[x].b = in[x*3+2];
+           /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
+              have to premultiply alpha (mix background and pixel according to the alpha channel).
+           */
+           out[x].r = (in[x*3+0]*ain[x])/255;
+           out[x].g = (in[x*3+1]*ain[x])/255;
+           out[x].b = (in[x*3+2]*ain[x])/255;
            out[x].a = ain[x];
        }
     }
@@ -207,7 +220,7 @@ void BitmapOutputDev::flush()
     gfxline_free(line);
 
     memset(rgbdev->getBitmap()->getAlphaPtr(), 0, rgbdev->getBitmap()->getWidth()*rgbdev->getBitmap()->getHeight());
-    memset(rgbdev->getBitmap()->getDataPtr(), 0, rgbdev->getBitmap()->getWidth()*rgbdev->getBitmap()->getHeight()*sizeof(SplashColor));
+    memset(rgbdev->getBitmap()->getDataPtr(), 0, rgbdev->getBitmap()->getRowSize()*rgbdev->getBitmap()->getHeight());
 
     free(img->data);img->data=0;free(img);img=0;
 }
@@ -237,28 +250,6 @@ void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, do
     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);
-
-    /*int width = this->rgbdev->getBitmap()->getWidth();
-    int height = this->rgbdev->getBitmap()->getHeight();
-    this->bboxpath = new SplashPath();
-    this->bboxpath->moveTo(0,0);
-    this->bboxpath->lineTo(width,0);
-    this->bboxpath->lineTo(width,height);
-    this->bboxpath->lineTo(0,height);
-    this->bboxpath->lineTo(0,0);
-
-    if(this->clipbitmap) {
-       delete this->clipbitmap;this->clipbitmap = 0;
-    }
-    this->clipbitmap = new SplashBitmap(width, height, 1, splashModeMono1, gFalse, gTrue);
-    if(this->clipdev) {
-       delete this->clipdev;this->clipdev = 0;
-    }
-    SplashScreenParams params;
-    params.type = splashScreenDispersed;
-    params.size = 0;
-    params.dotRadius = 0;
-    this->clipdev = new Splash(this->clipbitmap, 0, (SplashScreenParams*)0);*/
 }
 
 void BitmapOutputDev::endPage()
@@ -296,9 +287,9 @@ GBool BitmapOutputDev::useTilingPatternFill()
 
 GBool BitmapOutputDev::useShadedFills()
 {
-    clip0dev->useTilingPatternFill();
-    clip1dev->useTilingPatternFill();
-    return rgbdev->useTilingPatternFill();
+    clip0dev->useShadedFills();
+    clip1dev->useShadedFills();
+    return rgbdev->useShadedFills();
 }
 
 GBool BitmapOutputDev::useDrawForm()
@@ -437,8 +428,9 @@ void BitmapOutputDev::updateFillColor(GfxState *state)
 {
     rgbdev->updateFillColor(state);
     clip0dev->updateFillColor(state);
-    clip0dev->updateFillColor(state);
     clip1dev->updateFillColor(state);
+    if(!config_bitmapfonts)
+       gfxdev->updateFillColor(state);
 }
 void BitmapOutputDev::updateStrokeColor(GfxState *state)
 {
@@ -551,6 +543,8 @@ void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
     rgbdev->updateTextShift(state, shift);
     clip0dev->updateTextShift(state, shift);
     clip1dev->updateTextShift(state, shift);
+    if(!config_bitmapfonts)
+       gfxdev->updateTextShift(state, shift);
 }
 
 void BitmapOutputDev::stroke(GfxState *state)
@@ -568,6 +562,7 @@ void BitmapOutputDev::eoFill(GfxState *state)
     msg("<verbose> eoFill");
     rgbdev->eoFill(state);
 }
+#if (xpdfMajorVersion < 3) || (xpdfMinorVersion < 2) || (xpdfUpdateVersion < 7)
 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
                               int paintType, Dict *resDict,
                               double *mat, double *bbox,
@@ -577,6 +572,18 @@ void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
     msg("<verbose> tilingPatternFill");
     rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
 }
+#else
+void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
+                              int paintType, Dict *resDict,
+                              double *mat, double *bbox,
+                              int x0, int y0, int x1, int y1,
+                              double xStep, double yStep) 
+{
+    msg("<verbose> tilingPatternFill");
+    rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
+}
+#endif
+
 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading) 
 {
     msg("<verbose> functionShadedFill");
@@ -701,7 +708,6 @@ void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
           text */
        if(memcmp(clip0->getDataPtr(), clip1->getDataPtr(), width8*height)) {
            msg("<verbose> Char %d is affected by clipping", code);
-
            rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
            if(config_extrafontdata) {
                int oldrender = state->getRender();
@@ -711,7 +717,9 @@ void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
            }
        } else {
            /* this char is not at all affected by clipping. Now just find out whether the
-              bitmap we're currently working on needs to be dumped out first */
+              bitmap we're currently working on needs to be dumped out first,
+              by checking whether any of the char pixels in clip1dev is above any non-alpha
+              pixels in rgbdev */
     
            Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
            Guchar*charpixels = clip1dev->getBitmap()->getDataPtr();