added new output devices
authorkramm <kramm>
Sun, 28 Oct 2007 12:00:22 +0000 (12:00 +0000)
committerkramm <kramm>
Sun, 28 Oct 2007 12:00:22 +0000 (12:00 +0000)
lib/pdf/BitmapOutputDev.cc [new file with mode: 0644]
lib/pdf/BitmapOutputDev.h [new file with mode: 0644]
lib/pdf/CommonOutputDev.h [new file with mode: 0644]
lib/pdf/GFXOutputDev.cc
lib/pdf/GFXOutputDev.h
lib/pdf/Makefile.in
lib/pdf/pdf.cc
release.in

diff --git a/lib/pdf/BitmapOutputDev.cc b/lib/pdf/BitmapOutputDev.cc
new file mode 100644 (file)
index 0000000..fc0a158
--- /dev/null
@@ -0,0 +1,652 @@
+/* InfoOutputDev.h
+
+   Output Device which creates a bitmap.
+
+   Swftools is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   Swftools is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with swftools; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <memory.h>
+#include "BitmapOutputDev.h"
+#include "GFXOutputDev.h"
+#include "SplashBitmap.h"
+#include "../log.h"
+
+static SplashColor splash_white = {255,255,255};
+static SplashColor splash_black = {255,255,255};
+
+BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
+{
+    this->info = info;
+    this->doc = doc;
+    this->xref = doc->getXRef();
+    this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
+    this->alphadev = new SplashOutputDev(splashModeMono1, 1, gFalse, splash_black, gTrue, gTrue);
+    this->gfxdev = new GFXOutputDev(info, this->doc);
+    this->rgbdev->startDoc(this->xref);
+    this->alphadev->startDoc(this->xref);
+    memset(rgbdev->getBitmap()->getAlphaPtr(), 0, rgbdev->getBitmap()->getWidth()*rgbdev->getBitmap()->getHeight());
+
+    this->config_bitmapfonts = 0;
+}
+BitmapOutputDev::~BitmapOutputDev()
+{
+}
+
+void BitmapOutputDev::setDevice(gfxdevice_t*dev)
+{
+    this->dev = dev;
+    this->gfxdev->setDevice(dev);
+}
+void BitmapOutputDev::setMove(int x,int y)
+{
+}
+void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
+{
+}
+void BitmapOutputDev::setParameter(const char*key, const char*value)
+{
+}
+void BitmapOutputDev::preparePage(int pdfpage, int outputpage)
+{
+}
+
+void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
+{
+    *ymin = -1;
+    *xmin = width;
+    *xmax = 0;
+    int x,y;
+    for(y=0;y<height;y++) {
+       Guchar*a = &alpha[y*width];
+       for(x=0;x<width;x++) {
+           if(a[x]) break;
+       }
+       int left = x; //first occupied pixel from left
+       int right = x+1; //last non-occupied pixel from right
+       for(;x<width;x++) {
+           if(a[x]) right=x+1;
+       }
+
+       if(left!=width) {
+           if(*ymin<0) 
+               *ymin=y;
+           *ymax=y+1;
+           if(left<*xmin) *xmin = left;
+           if(right>*xmax) *xmax = right;
+       }
+    }
+    if(*xmin>=*xmax || *ymin>=*ymax) {
+       *xmin = 0;
+       *ymin = 0;
+       *xmax = 0;
+       *ymax = 0;
+    }
+}
+
+void BitmapOutputDev::flush()
+{
+    int width = rgbdev->getBitmapWidth();
+    int height = rgbdev->getBitmapHeight();
+    SplashColorPtr rgb = rgbdev->getBitmap()->getDataPtr();
+    Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
+
+    int xmin,ymin,xmax,ymax;
+    getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
+
+    msg("<verbose> Flushing graphics (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
+    
+    if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
+       return;
+
+    if(sizeof(SplashColor)!=3) {
+       msg("<error> sizeof(SplashColor)!=3");
+       return;
+    }
+    //xmin = ymin = 0;
+    //xmax = width;
+    //ymax = height;
+
+    int rangex = xmax-xmin;
+    int rangey = ymax-ymin;
+    gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t)); 
+    img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
+    img->width = rangex;
+    img->height = rangey;
+    int x,y;
+    for(y=0;y<rangey;y++) {
+       SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
+       gfxcolor_t*out = &img->data[y*rangex];
+       Guchar*ain = &alpha[(y+ymin)*width+xmax];
+       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];
+           out[x].a = ain[x];
+       }
+    }
+
+    gfxmatrix_t m;
+    m.tx = xmin;
+    m.ty = ymin;
+    m.m00 = m.m11 = 1;
+    m.m10 = m.m01 = 0;
+
+    gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
+    dev->fillbitmap(dev, line, img, &m, 0);
+    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));
+
+    free(img->data);img->data=0;free(img);img=0;
+}
+
+void BitmapOutputDev::startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2)
+{
+    msg("<verbose> startPage");
+    this->width = (int)x2 - (int)x1; //not used yet
+    this->height = (int)y2 - (int)y1;
+    rgbdev->startPage(pageNum, state, x1, y1, x2, y2);
+    alphadev->startPage(pageNum, state, x1, y1, x2, y2);
+}
+
+void BitmapOutputDev::endPage()
+{
+    msg("<verbose> endPage");
+    this->flush();
+
+    /* splash will now destroy alpha, and paint the 
+       background color into the "holes" in the bitmap */
+    rgbdev->endPage();
+    alphadev->endPage();
+}
+
+GBool BitmapOutputDev::upsideDown()
+{
+    rgbdev->upsideDown();
+    return alphadev->upsideDown();
+}
+
+GBool BitmapOutputDev::useDrawChar()
+{
+    rgbdev->useDrawChar();
+    return alphadev->useDrawChar();
+}
+
+GBool BitmapOutputDev::useTilingPatternFill()
+{
+    rgbdev->useTilingPatternFill();
+    return alphadev->useTilingPatternFill();
+}
+
+GBool BitmapOutputDev::useShadedFills()
+{
+    rgbdev->useTilingPatternFill();
+    return alphadev->useTilingPatternFill();
+}
+
+GBool BitmapOutputDev::useDrawForm()
+{
+    rgbdev->useDrawForm();
+    return alphadev->useDrawForm();
+}
+
+GBool BitmapOutputDev::interpretType3Chars()
+{
+    if(config_bitmapfonts) {
+       rgbdev->interpretType3Chars();
+       return alphadev->interpretType3Chars();
+    } else {
+       return gfxdev->interpretType3Chars();
+    }
+}
+
+GBool BitmapOutputDev::needNonText() 
+{
+    rgbdev->needNonText();
+    return alphadev->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) 
+{
+    rgbdev->setDefaultCTM(ctm);
+    alphadev->setDefaultCTM(ctm);
+}
+void BitmapOutputDev::saveState(GfxState *state) 
+{
+    rgbdev->saveState(state);
+    alphadev->saveState(state);
+}
+void BitmapOutputDev::restoreState(GfxState *state) 
+{
+    rgbdev->restoreState(state);
+    alphadev->restoreState(state);
+}
+void BitmapOutputDev::updateAll(GfxState *state)
+{
+    rgbdev->updateAll(state);
+    alphadev->updateAll(state);
+}
+void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
+{
+    rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
+    alphadev->updateCTM(state,m11,m12,m21,m22,m31,m32);
+}
+void BitmapOutputDev::updateLineDash(GfxState *state)
+{
+    rgbdev->updateLineDash(state);
+    alphadev->updateLineDash(state);
+}
+void BitmapOutputDev::updateFlatness(GfxState *state)
+{
+    rgbdev->updateFlatness(state);
+    alphadev->updateFlatness(state);
+}
+void BitmapOutputDev::updateLineJoin(GfxState *state)
+{
+    rgbdev->updateLineJoin(state);
+    alphadev->updateLineJoin(state);
+}
+void BitmapOutputDev::updateLineCap(GfxState *state)
+{
+    rgbdev->updateLineCap(state);
+    alphadev->updateLineCap(state);
+}
+void BitmapOutputDev::updateMiterLimit(GfxState *state)
+{
+    rgbdev->updateMiterLimit(state);
+    alphadev->updateMiterLimit(state);
+}
+void BitmapOutputDev::updateLineWidth(GfxState *state)
+{
+    rgbdev->updateLineWidth(state);
+    alphadev->updateLineWidth(state);
+}
+void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
+{
+    rgbdev->updateStrokeAdjust(state);
+    alphadev->updateStrokeAdjust(state);
+}
+void BitmapOutputDev::updateFillColorSpace(GfxState *state)
+{
+    rgbdev->updateFillColorSpace(state);
+    alphadev->updateFillColorSpace(state);
+}
+void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
+{
+    rgbdev->updateStrokeColorSpace(state);
+    alphadev->updateStrokeColorSpace(state);
+}
+void BitmapOutputDev::updateFillColor(GfxState *state)
+{
+    rgbdev->updateFillColor(state);
+    alphadev->updateFillColor(state);
+}
+void BitmapOutputDev::updateStrokeColor(GfxState *state)
+{
+    rgbdev->updateStrokeColor(state);
+    alphadev->updateStrokeColor(state);
+}
+void BitmapOutputDev::updateBlendMode(GfxState *state)
+{
+    rgbdev->updateBlendMode(state);
+    alphadev->updateBlendMode(state);
+}
+void BitmapOutputDev::updateFillOpacity(GfxState *state)
+{
+    rgbdev->updateFillOpacity(state);
+    alphadev->updateFillOpacity(state);
+}
+void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
+{
+    rgbdev->updateStrokeOpacity(state);
+    alphadev->updateStrokeOpacity(state);
+}
+void BitmapOutputDev::updateFillOverprint(GfxState *state)
+{
+    rgbdev->updateFillOverprint(state);
+    alphadev->updateFillOverprint(state);
+}
+void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
+{
+    rgbdev->updateStrokeOverprint(state);
+    alphadev->updateStrokeOverprint(state);
+}
+void BitmapOutputDev::updateTransfer(GfxState *state)
+{
+    rgbdev->updateTransfer(state);
+    alphadev->updateTransfer(state);
+}
+void BitmapOutputDev::updateFont(GfxState *state)
+{
+    rgbdev->updateFont(state);
+    alphadev->updateFont(state);
+    gfxdev->updateFont(state);
+}
+void BitmapOutputDev::updateTextMat(GfxState *state)
+{
+    rgbdev->updateTextMat(state);
+    alphadev->updateTextMat(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateCharSpace(GfxState *state)
+{
+    rgbdev->updateCharSpace(state);
+    alphadev->updateCharSpace(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateRender(GfxState *state)
+{
+    rgbdev->updateRender(state);
+    alphadev->updateRender(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateRise(GfxState *state)
+{
+    rgbdev->updateRise(state);
+    alphadev->updateRise(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateWordSpace(GfxState *state)
+{
+    rgbdev->updateWordSpace(state);
+    alphadev->updateWordSpace(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateHorizScaling(GfxState *state)
+{
+    rgbdev->updateHorizScaling(state);
+    alphadev->updateHorizScaling(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateTextPos(GfxState *state)
+{
+    rgbdev->updateTextPos(state);
+    alphadev->updateTextPos(state);
+    gfxdev->updateTextMat(state);
+}
+void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
+{
+    rgbdev->updateTextShift(state, shift);
+    alphadev->updateTextShift(state, shift);
+    gfxdev->updateTextMat(state);
+}
+
+void BitmapOutputDev::stroke(GfxState *state)
+{
+    msg("<verbose> stroke");
+    rgbdev->stroke(state);
+    alphadev->stroke(state);
+}
+void BitmapOutputDev::fill(GfxState *state)
+{
+    msg("<verbose> fill");
+    rgbdev->fill(state);
+    alphadev->fill(state);
+}
+void BitmapOutputDev::eoFill(GfxState *state)
+{
+    msg("<verbose> eoFill");
+    rgbdev->eoFill(state);
+    alphadev->eoFill(state);
+}
+void BitmapOutputDev::tilingPatternFill(GfxState *state, 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, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
+    alphadev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
+}
+GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading) 
+{
+    msg("<verbose> functionShadedFill");
+    rgbdev->functionShadedFill(state, shading);
+    return alphadev->functionShadedFill(state, shading);
+}
+GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
+{
+    msg("<verbose> axialShadedFill");
+    rgbdev->axialShadedFill(state, shading);
+    return alphadev->axialShadedFill(state, shading);
+}
+GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
+{
+    msg("<verbose> radialShadedFill");
+    rgbdev->radialShadedFill(state, shading);
+    return alphadev->radialShadedFill(state, shading);
+}
+void BitmapOutputDev::clip(GfxState *state)
+{
+    msg("<verbose> clip");
+    rgbdev->clip(state);
+    alphadev->clip(state);
+}
+void BitmapOutputDev::eoClip(GfxState *state)
+{
+    msg("<verbose> eoClip");
+    rgbdev->eoClip(state);
+    alphadev->eoClip(state);
+}
+void BitmapOutputDev::clipToStrokePath(GfxState *state)
+{
+    msg("<verbose> clipToStrokePath");
+    rgbdev->clipToStrokePath(state);
+    alphadev->clipToStrokePath(state);
+}
+
+void BitmapOutputDev::beginStringOp(GfxState *state)
+{
+    msg("<verbose> beginStringOp");
+    if(this->config_bitmapfonts) {
+       rgbdev->beginStringOp(state);
+       alphadev->beginStringOp(state);
+    } else {
+       gfxdev->beginStringOp(state);
+    }
+}
+void BitmapOutputDev::endStringOp(GfxState *state)
+{
+    msg("<verbose> endStringOp");
+    if(this->config_bitmapfonts) {
+       rgbdev->endStringOp(state);
+       alphadev->endStringOp(state);
+    } else {
+       gfxdev->endStringOp(state);
+    }
+}
+void BitmapOutputDev::beginString(GfxState *state, GString *s)
+{
+    msg("<verbose> beginString");
+    if(this->config_bitmapfonts) {
+       rgbdev->beginString(state, s);
+       alphadev->beginString(state, s);
+    } else {
+       gfxdev->beginString(state, s);
+    }
+}
+void BitmapOutputDev::endString(GfxState *state)
+{
+    msg("<verbose> endString");
+    if(this->config_bitmapfonts) {
+       rgbdev->endString(state);
+       alphadev->endString(state);
+    } else {
+       gfxdev->endString(state);
+    }
+}
+void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
+                     double dx, double dy,
+                     double originX, double originY,
+                     CharCode code, int nBytes, Unicode *u, int uLen)
+{
+    msg("<verbose> drawChar");
+    flush();
+    if(this->config_bitmapfonts) {
+       rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+       alphadev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+    } else {
+       gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+    }
+}
+void BitmapOutputDev::drawString(GfxState *state, GString *s)
+{
+    msg("<verbose> drawString");
+    if(this->config_bitmapfonts) {
+       rgbdev->drawString(state, s);
+       alphadev->drawString(state, s);
+    } else {
+       gfxdev->drawString(state, s);
+    }
+}
+void BitmapOutputDev::endTextObject(GfxState *state)
+{
+    msg("<verbose> endTextObject");
+    if(this->config_bitmapfonts) {
+       rgbdev->endTextObject(state);
+       alphadev->endTextObject(state);
+    } else {
+       gfxdev->endType3Char(state);
+    }
+}
+GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
+                            double dx, double dy,
+                            CharCode code, Unicode *u, int uLen)
+{
+    msg("<verbose> beginType3Char");
+    if(this->config_bitmapfonts) {
+       rgbdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
+       return alphadev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
+    } else {
+       return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
+    }
+}
+void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
+{
+    msg("<verbose> type3D0");
+    if(this->config_bitmapfonts) {
+       rgbdev->type3D0(state, wx, wy);
+       alphadev->type3D0(state, wx, wy);
+    } else {
+       return gfxdev->type3D0(state, wx, wy);
+    }
+}
+void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
+{
+    msg("<verbose> type3D1");
+    if(this->config_bitmapfonts) {
+       rgbdev->type3D1(state, wx, wy, llx, lly, urx, ury);
+       alphadev->type3D1(state, wx, wy, llx, lly, urx, ury);
+    } else {
+       return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
+    }
+}
+void BitmapOutputDev::endType3Char(GfxState *state)
+{
+    msg("<verbose> endType3Char");
+    if(this->config_bitmapfonts) {
+       rgbdev->endType3Char(state);
+       alphadev->endType3Char(state);
+    } else {
+       gfxdev->endType3Char(state);
+    }
+}
+void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
+                          int width, int height, GBool invert,
+                          GBool inlineImg)
+{
+    msg("<verbose> drawImageMask");
+    rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
+    alphadev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
+}
+void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
+                      int width, int height, GfxImageColorMap *colorMap,
+                      int *maskColors, GBool inlineImg)
+{
+    msg("<verbose> drawImage");
+    rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
+    alphadev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
+}
+void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
+                            int width, int height,
+                            GfxImageColorMap *colorMap,
+                            Stream *maskStr, int maskWidth, int maskHeight,
+                            GBool maskInvert)
+{
+    msg("<verbose> drawMaskedImage");
+    rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
+    alphadev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
+}
+void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
+                                int width, int height,
+                                GfxImageColorMap *colorMap,
+                                Stream *maskStr,
+                                int maskWidth, int maskHeight,
+                                GfxImageColorMap *maskColorMap)
+{
+    msg("<verbose> drawSoftMaskedImage");
+    rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
+    alphadev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
+}
+void BitmapOutputDev::drawForm(Ref id)
+{
+    msg("<verbose> drawForm");
+    rgbdev->drawForm(id);
+    alphadev->drawForm(id);
+}
+void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
+                                   GfxColorSpace *blendingColorSpace,
+                                   GBool isolated, GBool knockout,
+                                   GBool forSoftMask)
+{
+    msg("<verbose> beginTransparencyGroup");
+    rgbdev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
+    alphadev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
+}
+void BitmapOutputDev::endTransparencyGroup(GfxState *state)
+{
+    msg("<verbose> endTransparencyGroup");
+    rgbdev->endTransparencyGroup(state);
+    alphadev->endTransparencyGroup(state);
+}
+void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
+{
+    msg("<verbose> paintTransparencyGroup");
+    rgbdev->paintTransparencyGroup(state,bbox);
+    alphadev->paintTransparencyGroup(state,bbox);
+}
+void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
+{
+    msg("<verbose> setSoftMask");
+    rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
+    alphadev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
+}
+void BitmapOutputDev::clearSoftMask(GfxState *state)
+{
+    msg("<verbose> clearSoftMask");
+    rgbdev->clearSoftMask(state);
+    alphadev->clearSoftMask(state);
+}
diff --git a/lib/pdf/BitmapOutputDev.h b/lib/pdf/BitmapOutputDev.h
new file mode 100644 (file)
index 0000000..3e821c7
--- /dev/null
@@ -0,0 +1,175 @@
+/* BitmapOutputDev.cc
+   Output device which creates a bitmap.
+
+   This file is part of swftools.
+
+   Swftools is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   Swftools is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with swftools; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef __BitmapOutputDev_h__
+#define __BitmapOutputDev_h__
+
+#include "../gfxdevice.h"
+#include "../gfxsource.h"
+#include "../gfxtools.h"
+
+#include "config.h"
+#include "GFXOutputDev.h"
+#include "InfoOutputDev.h"
+#include "PDFDoc.h"
+#include "CommonOutputDev.h"
+
+class BitmapOutputDev: public CommonOutputDev {
+public:
+    BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc);
+    virtual ~BitmapOutputDev();
+   
+    // CommonOutputDev:
+    virtual void setDevice(gfxdevice_t*dev);
+    virtual void setMove(int x,int y);
+    virtual void setClip(int x1,int y1,int x2,int y2);
+    virtual void setParameter(const char*key, const char*value);
+    virtual void preparePage(int pdfpage, int outputpage);
+
+    // OutputDev:
+    virtual GBool upsideDown();
+    virtual GBool useDrawChar();
+    virtual GBool useTilingPatternFill();
+    virtual GBool useShadedFills();
+    virtual GBool useDrawForm();
+    virtual GBool interpretType3Chars();
+    virtual GBool needNonText();
+    virtual void setDefaultCTM(double *ctm);
+/*    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, double x1,double y1,double x2,double y2);
+    virtual void endPage();
+
+    virtual void saveState(GfxState *state);
+    virtual void restoreState(GfxState *state);
+
+    virtual void updateAll(GfxState *state);
+    virtual void updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32);
+    virtual void updateLineDash(GfxState *state);
+    virtual void updateFlatness(GfxState *state);
+    virtual void updateLineJoin(GfxState *state);
+    virtual void updateLineCap(GfxState *state);
+    virtual void updateMiterLimit(GfxState *state);
+    virtual void updateLineWidth(GfxState *state);
+    virtual void updateStrokeAdjust(GfxState *state);
+    virtual void updateFillColorSpace(GfxState *state);
+    virtual void updateStrokeColorSpace(GfxState *state);
+    virtual void updateFillColor(GfxState *state);
+    virtual void updateStrokeColor(GfxState *state);
+    virtual void updateBlendMode(GfxState *state);
+    virtual void updateFillOpacity(GfxState *state);
+    virtual void updateStrokeOpacity(GfxState *state);
+    virtual void updateFillOverprint(GfxState *state);
+    virtual void updateStrokeOverprint(GfxState *state);
+    virtual void updateTransfer(GfxState *state);
+    virtual void updateFont(GfxState *state);
+    virtual void updateTextMat(GfxState *state);
+    virtual void updateCharSpace(GfxState *state);
+    virtual void updateRender(GfxState *state);
+    virtual void updateRise(GfxState *state);
+    virtual void updateWordSpace(GfxState *state);
+    virtual void updateHorizScaling(GfxState *state);
+    virtual void updateTextPos(GfxState *state);
+    virtual void updateTextShift(GfxState *state, double shift);
+
+    virtual void stroke(GfxState *state);
+    virtual void fill(GfxState *state);
+    virtual void eoFill(GfxState *state);
+    virtual void tilingPatternFill(GfxState *state, Object *str,
+                                  int paintType, Dict *resDict,
+                                  double *mat, double *bbox,
+                                  int x0, int y0, int x1, int y1,
+                                  double xStep, double yStep);
+    virtual GBool functionShadedFill(GfxState *state,
+                                    GfxFunctionShading *shading);
+    virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
+    virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
+
+    virtual void clip(GfxState *state);
+    virtual void eoClip(GfxState *state);
+    virtual void clipToStrokePath(GfxState *state);
+
+    virtual void beginStringOp(GfxState *state);
+    virtual void endStringOp(GfxState *state);
+    virtual void beginString(GfxState *state, GString *s);
+    virtual void endString(GfxState *state);
+    virtual void drawChar(GfxState *state, double x, double y,
+                         double dx, double dy,
+                         double originX, double originY,
+                         CharCode code, int nBytes, Unicode *u, int uLen);
+    virtual void drawString(GfxState *state, GString *s);
+    virtual GBool beginType3Char(GfxState *state, double x, double y,
+                                double dx, double dy,
+                                CharCode code, Unicode *u, int uLen);
+    virtual void endType3Char(GfxState *state);
+    virtual void endTextObject(GfxState *state);
+
+    virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
+                              int width, int height, GBool invert,
+                              GBool inlineImg);
+    virtual void drawImage(GfxState *state, Object *ref, Stream *str,
+                          int width, int height, GfxImageColorMap *colorMap,
+                          int *maskColors, GBool inlineImg);
+    virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
+                                int width, int height,
+                                GfxImageColorMap *colorMap,
+                                Stream *maskStr, int maskWidth, int maskHeight,
+                                GBool maskInvert);
+    virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
+                                    int width, int height,
+                                    GfxImageColorMap *colorMap,
+                                    Stream *maskStr,
+                                    int maskWidth, int maskHeight,
+                                    GfxImageColorMap *maskColorMap);
+
+    virtual void type3D0(GfxState *state, double wx, double wy);
+    virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
+
+    virtual void drawForm(Ref id);
+
+    virtual void beginTransparencyGroup(GfxState *state, double *bbox,
+                                       GfxColorSpace *blendingColorSpace,
+                                       GBool isolated, GBool knockout,
+                                       GBool forSoftMask);
+    virtual void endTransparencyGroup(GfxState *state);
+    virtual void paintTransparencyGroup(GfxState *state, double *bbox);
+    virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
+    virtual void clearSoftMask(GfxState *state);
+
+private:
+    void flush();
+
+    char config_bitmapfonts;
+
+    int width, height;
+    PDFDoc*doc;
+    XRef*xref;
+    SplashOutputDev*rgbdev;
+    SplashOutputDev*alphadev;
+    GFXOutputDev*gfxdev;
+    InfoOutputDev*info;
+    gfxdevice_t*dev;
+};
+
+#endif
diff --git a/lib/pdf/CommonOutputDev.h b/lib/pdf/CommonOutputDev.h
new file mode 100644 (file)
index 0000000..03b2f46
--- /dev/null
@@ -0,0 +1,35 @@
+/* InfoOutputDev.h
+   Superclass for BitmapOutputDev, GFXOutputDev etc.
+
+   This file is part of swftools.
+
+   Swftools is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   Swftools is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with swftools; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef __commonoutputdev_h__
+#define __commonoutputdev_h__
+
+#include "OutputDev.h"
+
+class CommonOutputDev: public OutputDev
+{
+    public:
+    virtual void setDevice(gfxdevice_t*dev) = 0;
+    virtual void setMove(int x,int y) = 0;
+    virtual void setClip(int x1,int y1,int x2,int y2) = 0;
+    virtual void setParameter(const char*key, const char*value) = 0;
+  
+    virtual void preparePage(int pdfpage, int outputpage) = 0;
+};
+#endif //__deviceinterface_h__
index a1ddba9..da5df32 100644 (file)
@@ -31,9 +31,6 @@
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#ifdef HAVE_FONTCONFIG
-#include <fontconfig.h>
-#endif
 //xpdf header files
 #include "config.h"
 #include "gfile.h"
 //xpdf header files
 #include "config.h"
 #include "gfile.h"
@@ -338,8 +335,12 @@ DisplayFontParam *GFXGlobalParams::getDisplayFont(GString *fontName)
     return GlobalParams::getDisplayFont(fontName);
 }
 
     return GlobalParams::getDisplayFont(fontName);
 }
 
-GFXOutputDev::GFXOutputDev(parameter_t*p)
+GFXOutputDev::GFXOutputDev(InfoOutputDev*info, PDFDoc*doc)
 {
 {
+    this->info = info;
+    this->doc = doc;
+    this->xref = doc->getXRef();
+
     this->jpeginfo = 0;
     this->textmodeinfo = 0;
     this->linkinfo = 0;
     this->jpeginfo = 0;
     this->textmodeinfo = 0;
     this->linkinfo = 0;
@@ -363,52 +364,39 @@ GFXOutputDev::GFXOutputDev(parameter_t*p)
     this->pages = 0;
     this->pagebuflen = 0;
     this->pagepos = 0;
     this->pages = 0;
     this->pagebuflen = 0;
     this->pagepos = 0;
-    this->config_use_fontconfig=1;
     this->config_break_on_warning=0;
     this->config_remapunicode=0;
     this->config_transparent=0;
     this->config_extrafontdata = 0;
 
     this->config_break_on_warning=0;
     this->config_remapunicode=0;
     this->config_transparent=0;
     this->config_extrafontdata = 0;
 
-    this->parameters = p;
-    
     this->gfxfontlist = gfxfontlist_create();
   
     memset(states, 0, sizeof(states));
     this->gfxfontlist = gfxfontlist_create();
   
     memset(states, 0, sizeof(states));
-
-    /* configure device */
-    while(p) {
-        setParameter(p->name, p->value);
-       p = p->next;
-    }
 };
 
 void GFXOutputDev::setParameter(const char*key, const char*value)
 {
     if(!strcmp(key,"breakonwarning")) {
        this->config_break_on_warning = atoi(value);
 };
 
 void GFXOutputDev::setParameter(const char*key, const char*value)
 {
     if(!strcmp(key,"breakonwarning")) {
        this->config_break_on_warning = atoi(value);
-    } else if(!strcmp(key,"fontconfig")) {
-        this->config_use_fontconfig = atoi(value);
     } else if(!strcmp(key,"remapunicode")) {
         this->config_remapunicode = atoi(value);
     } else if(!strcmp(key,"transparent")) {
         this->config_transparent = atoi(value);
     } else if(!strcmp(key,"extrafontdata")) {
         this->config_extrafontdata = atoi(value);
     } else if(!strcmp(key,"remapunicode")) {
         this->config_remapunicode = atoi(value);
     } else if(!strcmp(key,"transparent")) {
         this->config_transparent = atoi(value);
     } else if(!strcmp(key,"extrafontdata")) {
         this->config_extrafontdata = atoi(value);
+    } else if(!strcmp(key,"help")) {
+       printf("\nPDF layer options:\n");
+       printf("breakonwarning=0/1  Abort conversion if graphic objects are found which\n");
+       printf("                    are not 100%% supported\n");
+       printf("transparent=0/1     Make PDF transparent (alpha background)\n");
+       printf("extrafontdata=0/1   Store Type3 characters and capture characters\n");
     }
     }
+    
 }
   
 void GFXOutputDev::setDevice(gfxdevice_t*dev)
 {
 }
   
 void GFXOutputDev::setDevice(gfxdevice_t*dev)
 {
-    parameter_t*p = this->parameters;
-
-    /* pass parameters to output device */
     this->device = dev;
     this->device = dev;
-    if(this->device) {
-       while(p) {
-           this->device->setparameter(this->device, p->name, p->value);
-           p = p->next;
-       }
-    }
 }
   
 void GFXOutputDev::setMove(int x,int y)
 }
   
 void GFXOutputDev::setMove(int x,int y)
@@ -657,6 +645,10 @@ GBool GFXOutputDev::needNonText()
 void GFXOutputDev::endPage() 
 {
     msg("<verbose> endPage");
 void GFXOutputDev::endPage() 
 {
     msg("<verbose> endPage");
+    if(outer_clip_box) {
+       device->endclip(device);
+       outer_clip_box = 0;
+    }
 }
 
 #define STROKE_FILL 1
 }
 
 #define STROKE_FILL 1
@@ -826,14 +818,6 @@ void GFXOutputDev::clipToStrokePath(GfxState *state)
     gfxline_free(line);
 }
 
     gfxline_free(line);
 }
 
-void GFXOutputDev::endframe()
-{
-    if(outer_clip_box) {
-       device->endclip(device);
-       outer_clip_box = 0;
-    }
-}
-
 void GFXOutputDev::finish()
 {
     if(outer_clip_box) {
 void GFXOutputDev::finish()
 {
     if(outer_clip_box) {
@@ -1108,18 +1092,6 @@ void GFXOutputDev::endType3Char(GfxState *state)
     msg("<debug> endType3Char");
 }
 
     msg("<debug> endType3Char");
 }
 
-void GFXOutputDev::startFrame(int width, int height) 
-{
-    if(outer_clip_box) {
-       device->endclip(device);
-       outer_clip_box = 0;
-    }
-
-    device->startpage(device, width, height);
-    this->width = width;
-    this->height = height;
-}
-
 void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) 
 {
     this->currentpage = pageNum;
 void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) 
 {
     this->currentpage = pageNum;
@@ -1452,11 +1424,6 @@ void GFXOutputDev::updateStrokeColor(GfxState *state)
     state->getStrokeRGB(&rgb);
 }
 
     state->getStrokeRGB(&rgb);
 }
 
-void GFXOutputDev::setXRef(PDFDoc*doc, XRef *xref) 
-{
-    this->doc = doc;
-    this->xref = xref;
-}
 
 gfxfont_t* createGfxFont(GfxFont*xpdffont, FontInfo*src)
 {
 
 gfxfont_t* createGfxFont(GfxFont*xpdffont, FontInfo*src)
 {
@@ -2222,13 +2189,11 @@ void GFXOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
                                      GBool forSoftMask)
 {
     const char*colormodename = "";
                                      GBool forSoftMask)
 {
     const char*colormodename = "";
-    BBox rect = mkBBox(state, bbox, this->width, this->height);
 
     if(blendingColorSpace) {
        colormodename = GfxColorSpace::getColorSpaceModeName(blendingColorSpace->getMode());
     }
     dbg("beginTransparencyGroup %.1f/%.1f/%.1f/%.1f %s isolated=%d knockout=%d forsoftmask=%d", bbox[0],bbox[1],bbox[2],bbox[3], colormodename, isolated, knockout, forSoftMask);
 
     if(blendingColorSpace) {
        colormodename = GfxColorSpace::getColorSpaceModeName(blendingColorSpace->getMode());
     }
     dbg("beginTransparencyGroup %.1f/%.1f/%.1f/%.1f %s isolated=%d knockout=%d forsoftmask=%d", bbox[0],bbox[1],bbox[2],bbox[3], colormodename, isolated, knockout, forSoftMask);
-    dbg("using clipping rect %f/%f/%f/%f\n", rect.posx,rect.posy,rect.width,rect.height);
     msg("<verbose> beginTransparencyGroup %.1f/%.1f/%.1f/%.1f %s isolated=%d knockout=%d forsoftmask=%d", bbox[0],bbox[1],bbox[2],bbox[3], colormodename, isolated, knockout, forSoftMask);
     
     states[statepos].createsoftmask |= forSoftMask;
     msg("<verbose> beginTransparencyGroup %.1f/%.1f/%.1f/%.1f %s isolated=%d knockout=%d forsoftmask=%d", bbox[0],bbox[1],bbox[2],bbox[3], colormodename, isolated, knockout, forSoftMask);
     
     states[statepos].createsoftmask |= forSoftMask;
index 645283a..0f41f75 100644 (file)
@@ -8,13 +8,8 @@
 #include "config.h"
 #include "InfoOutputDev.h"
 #include "PDFDoc.h"
 #include "config.h"
 #include "InfoOutputDev.h"
 #include "PDFDoc.h"
-
-typedef struct _fontlist
-{
-    char*filename;
-    gfxfont_t*font;
-    _fontlist*next;
-} fontlist_t;
+#include "GlobalParams.h"
+#include "CommonOutputDev.h"
 
 class GFXOutputState {
     public:
 
 class GFXOutputState {
     public:
@@ -45,29 +40,21 @@ void addGlobalFont(const char*filename);
 void addGlobalLanguageDir(const char*dir);
 void addGlobalFontDir(const char*dirname);
 
 void addGlobalLanguageDir(const char*dir);
 void addGlobalFontDir(const char*dirname);
 
-class GFXOutputDev:  public OutputDev {
+class GFXOutputDev:  public CommonOutputDev {
 public:
   gfxdevice_t* device;
 
 public:
   gfxdevice_t* device;
 
-  // Constructor.
-  GFXOutputDev(parameter_t*p);
-  void setDevice(gfxdevice_t*dev);
-
-  // Destructor.
+  GFXOutputDev(InfoOutputDev*info, PDFDoc*doc);
   virtual ~GFXOutputDev() ;
 
   virtual ~GFXOutputDev() ;
 
-  void setMove(int x,int y);
-  void setClip(int x1,int y1,int x2,int y2);
-  void setParameter(const char*key, const char*value);
-
-  void setInfo(InfoOutputDev*info) {this->info = info;}
+  virtual void setDevice(gfxdevice_t*dev);
+  virtual void setMove(int x,int y);
+  virtual void setClip(int x1,int y1,int x2,int y2);
+  virtual void setParameter(const char*key, const char*value);
   
   // Start a page.
   
   // Start a page.
-  void startFrame(int width, int height);
-
   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
-
-  void endframe();
+  virtual void endPage();
 
   //----- get info about output device
 
 
   //----- get info about output device
 
@@ -82,10 +69,6 @@ public:
   
   //virtual GBool useShadedFills() { return gTrue; }
 
   
   //virtual GBool useShadedFills() { return gTrue; }
 
-  //----- initialization and control
-
-  void setXRef(PDFDoc*doc, XRef *xref);
-
   //----- link borders
   virtual void processLink(Link *link, Catalog *catalog);
 
   //----- link borders
   virtual void processLink(Link *link, Catalog *catalog);
 
@@ -189,7 +172,7 @@ public:
   virtual void type3D0(GfxState *state, double wx, double wy);
   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
 
   virtual void type3D0(GfxState *state, double wx, double wy);
   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
 
-  void preparePage(int pdfpage, int outputpage);
+  virtual void preparePage(int pdfpage, int outputpage);
 
   char* searchForSuitableFont(GfxFont*gfxFont);
 
 
   char* searchForSuitableFont(GfxFont*gfxFont);
 
@@ -198,7 +181,6 @@ public:
   virtual GBool useDrawForm();
   virtual void drawForm(Ref id);
   virtual GBool needNonText();
   virtual GBool useDrawForm();
   virtual void drawForm(Ref id);
   virtual GBool needNonText();
-  virtual void endPage();
 
   //virtual void dump();
   //virtual void beginStringOp(GfxState *state);
 
   //virtual void dump();
   //virtual void beginStringOp(GfxState *state);
@@ -265,8 +247,6 @@ public:
   int clipmovex;
   int clipmovey;
 
   int clipmovex;
   int clipmovey;
 
-  double width,height;
-
   gfxline_t* current_text_stroke;
   gfxline_t* current_text_clip;
   char* current_font_id;
   gfxline_t* current_text_stroke;
   gfxline_t* current_text_clip;
   char* current_font_id;
index d28bb45..1d5eb41 100644 (file)
@@ -8,7 +8,7 @@ all: ../libpdf$(A) pdf2swf
 
 libpdf: ../libpdf$(A)
 
 
 libpdf: ../libpdf$(A)
 
-libpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) pdf.$(O) fonts.$(O)
+libpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) pdf.$(O) fonts.$(O)
 
 xpdf_objects =  xpdf/GHash.$(O) xpdf/GList.$(O) xpdf/GString.$(O) xpdf/gmem.$(O) xpdf/gfile.$(O) \
                  xpdf/FoFiTrueType.$(O) xpdf/FoFiType1.$(O) xpdf/FoFiType1C.$(O) xpdf/FoFiBase.$(O) xpdf/FoFiEncodings.$(O) \
 
 xpdf_objects =  xpdf/GHash.$(O) xpdf/GList.$(O) xpdf/GString.$(O) xpdf/gmem.$(O) xpdf/gfile.$(O) \
                  xpdf/FoFiTrueType.$(O) xpdf/FoFiType1.$(O) xpdf/FoFiType1C.$(O) xpdf/FoFiBase.$(O) xpdf/FoFiEncodings.$(O) \
@@ -34,6 +34,8 @@ GFXOutputDev.$(O): GFXOutputDev.cc GFXOutputDev.h ../devices/artsutils.c
        $(CC) -I ./ -I xpdf GFXOutputDev.cc -o $@
 InfoOutputDev.$(O): InfoOutputDev.cc InfoOutputDev.h
        $(CC) -I ./ -I xpdf InfoOutputDev.cc -o $@
        $(CC) -I ./ -I xpdf GFXOutputDev.cc -o $@
 InfoOutputDev.$(O): InfoOutputDev.cc InfoOutputDev.h
        $(CC) -I ./ -I xpdf InfoOutputDev.cc -o $@
+BitmapOutputDev.$(O): BitmapOutputDev.cc BitmapOutputDev.h
+       $(CC) -I ./ -I xpdf BitmapOutputDev.cc -o $@
 pdf.$(O): pdf.cc GFXOutputDev.h InfoOutputDev.h
        $(CC) -I ./ -I xpdf pdf.cc -o $@
 
 pdf.$(O): pdf.cc GFXOutputDev.h InfoOutputDev.h
        $(CC) -I ./ -I xpdf pdf.cc -o $@
 
index f06949e..00eee04 100644 (file)
@@ -5,6 +5,7 @@
 #include "GlobalParams.h"
 #include "InfoOutputDev.h"
 #include "GFXOutputDev.h"
 #include "GlobalParams.h"
 #include "InfoOutputDev.h"
 #include "GFXOutputDev.h"
+#include "BitmapOutputDev.h"
 #include "../mem.h"
 #include "pdf.h"
 #define NO_ARGPARSER
 #include "../mem.h"
 #include "pdf.h"
 #define NO_ARGPARSER
@@ -36,7 +37,7 @@ typedef struct _pdf_doc_internal
     PDFDoc*doc;
     Object docinfo;
     InfoOutputDev*info;
     PDFDoc*doc;
     Object docinfo;
     InfoOutputDev*info;
-    GFXOutputDev*outputDev;
+    CommonOutputDev*outputDev;
     pdf_page_info_t*pages;
 } pdf_doc_internal_t;
 
     pdf_page_info_t*pages;
 } pdf_doc_internal_t;
 
@@ -46,7 +47,7 @@ typedef struct _pdf_page_internal
 
 typedef struct _dev_output_internal
 {
 
 typedef struct _dev_output_internal
 {
-    GFXOutputDev*outputDev;
+    CommonOutputDev*outputDev;
 } dev_output_internal_t;
 
 
 } dev_output_internal_t;
 
 
@@ -67,7 +68,7 @@ void pdfpage_destroy(gfxpage_t*pdf_page)
     free(pdf_page);pdf_page=0;
 }
 
     free(pdf_page);pdf_page=0;
 }
 
-void render2(gfxpage_t*page, gfxdevice_t*output)
+void render2(gfxpage_t*page, gfxdevice_t*dev)
 {
     pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
 
 {
     pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
 
@@ -81,38 +82,41 @@ void render2(gfxpage_t*page, gfxdevice_t*output)
        return;
     }
 
        return;
     }
 
+    pi->outputDev->setDevice(dev);
     if(pi->protect) {
     if(pi->protect) {
-       gfxdevice_t*dev = pi->outputDev->device;
         dev->setparameter(dev, "protect", "1");
     }
         dev->setparameter(dev, "protect", "1");
     }
-    pi->outputDev->setInfo(pi->info);
-    pi->outputDev->setXRef(pi->doc, pi->doc->getXRef());
+    
+    /* pass global parameters to output device */
+    parameter_t*p = device_config;
+    while(p) {
+       dev->setparameter(dev, p->name, p->value);
+       p = p->next;
+    }
     pi->doc->displayPage((OutputDev*)pi->outputDev, page->nr, zoom, zoom, /*rotate*/0, true, true, /*doLinks*/(int)1);
     pi->doc->processLinks((OutputDev*)pi->outputDev, page->nr);
     pi->doc->displayPage((OutputDev*)pi->outputDev, page->nr, zoom, zoom, /*rotate*/0, true, true, /*doLinks*/(int)1);
     pi->doc->processLinks((OutputDev*)pi->outputDev, page->nr);
-    pi->outputDev->endframe();
+    pi->outputDev->setDevice(0);
 }
 
     
 void pdfpage_render(gfxpage_t*page, gfxdevice_t*output)
 {
     pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
 }
 
     
 void pdfpage_render(gfxpage_t*page, gfxdevice_t*output)
 {
     pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
-    pi->outputDev->setDevice(output);
     pi->outputDev->setMove(0,0);
     pi->outputDev->setClip(0,0,0,0);
     render2(page, output);
     pi->outputDev->setMove(0,0);
     pi->outputDev->setClip(0,0,0,0);
     render2(page, output);
-    pi->outputDev->setDevice(0);
 }
 
 void pdfpage_rendersection(gfxpage_t*page, gfxdevice_t*output, gfxcoord_t x, gfxcoord_t y, gfxcoord_t _x1, gfxcoord_t _y1, gfxcoord_t _x2, gfxcoord_t _y2)
 {
 }
 
 void pdfpage_rendersection(gfxpage_t*page, gfxdevice_t*output, gfxcoord_t x, gfxcoord_t y, gfxcoord_t _x1, gfxcoord_t _y1, gfxcoord_t _x2, gfxcoord_t _y2)
 {
-    int x1=(int)_x1,y1=(int)_y1,x2=(int)_x2,y2=(int)_y2;
     pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
     pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
-    pi->outputDev->setDevice(output);
-    pi->outputDev->setMove((int)x,(int)y);
+
+    int x1=(int)_x1,y1=(int)_y1,x2=(int)_x2,y2=(int)_y2;
     if((x1|y1|x2|y2)==0) x2++;
     if((x1|y1|x2|y2)==0) x2++;
+
+    pi->outputDev->setMove((int)x,(int)y);
     pi->outputDev->setClip((int)x1,(int)y1,(int)x2,(int)y2);
     render2(page, output);
     pi->outputDev->setClip((int)x1,(int)y1,(int)x2,(int)y2);
     render2(page, output);
-    pi->outputDev->setDevice(0);
 }
 
 static int globalparams_count=0;
 }
 
 static int globalparams_count=0;
@@ -121,6 +125,9 @@ void pdf_doc_destroy(gfxdocument_t*gfx)
 {
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal;
 
 {
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal;
 
+    if(i->outputDev) {
+       delete i->outputDev;i->outputDev=0;
+    }
     delete i->doc; i->doc=0;
     free(i->pages); i->pages = 0;
 
     delete i->doc; i->doc=0;
     free(i->pages); i->pages = 0;
 
@@ -138,18 +145,18 @@ void pdf_doc_destroy(gfxdocument_t*gfx)
        global_page_range = 0;
     }
     
        global_page_range = 0;
     }
     
-    globalparams_count--;
+    /*globalparams_count--;
     if(!globalparams_count) {
        delete globalParams;
        globalParams = 0;
        globalparams_count = 0;
     if(!globalparams_count) {
        delete globalParams;
        globalParams = 0;
        globalparams_count = 0;
-    }
+    }*/
 }
 
 void pdf_doc_set_parameter(gfxdocument_t*gfx, const char*name, const char*value)
 {
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal;
 }
 
 void pdf_doc_set_parameter(gfxdocument_t*gfx, const char*name, const char*value)
 {
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal;
-    GFXOutputDev*o = i->outputDev;
+    CommonOutputDev*o = i->outputDev;
     if(!strcmp(name, "pagemap")) {
        int pdfpage=0, outputpage=0;
        sscanf(value,"%d:%d", &pdfpage, &outputpage);
     if(!strcmp(name, "pagemap")) {
        int pdfpage=0, outputpage=0;
        sscanf(value,"%d:%d", &pdfpage, &outputpage);
@@ -302,18 +309,19 @@ static void pdf_set_parameter(const char*name, const char*value)
        ppm_dpi = atoi(value);
        sprintf(buf, "%f", (double)ppm_dpi/(double)zoom);
        storeDeviceParameter("ppmsubpixels", buf);
        ppm_dpi = atoi(value);
        sprintf(buf, "%f", (double)ppm_dpi/(double)zoom);
        storeDeviceParameter("ppmsubpixels", buf);
+    } else if(!strcmp(name, "help")) {
+       printf("\nPDF device global parameters:\n");
+       printf("fontdir=<dir>   a directory with additional fonts\n");
+       printf("font=<filename> an dditional font filename\n");
+       printf("pages=<range>   the range of pages to convert (example: pages=1-100,210-)\n");
+       printf("zoom=<dpi>      the resultion (default: 72)\n");
     } else {
        storeDeviceParameter(name,value);
     } else {
        storeDeviceParameter(name,value);
-    }
+    } 
 }
 
 static gfxdocument_t*pdf_open(const char*filename)
 {
 }
 
 static gfxdocument_t*pdf_open(const char*filename)
 {
-    if(!globalParams) {
-        globalParams = new GFXGlobalParams();
-       globalparams_count++;
-    }
-    
     gfxdocument_t*pdf_doc = (gfxdocument_t*)malloc(sizeof(gfxdocument_t));
     memset(pdf_doc, 0, sizeof(gfxdocument_t));
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)malloc(sizeof(pdf_doc_internal_t));
     gfxdocument_t*pdf_doc = (gfxdocument_t*)malloc(sizeof(gfxdocument_t));
     memset(pdf_doc, 0, sizeof(gfxdocument_t));
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)malloc(sizeof(pdf_doc_internal_t));
@@ -381,8 +389,21 @@ static gfxdocument_t*pdf_open(const char*filename)
            i->pages[t-1].has_info = 1;
        }
     }
            i->pages[t-1].has_info = 1;
        }
     }
-    i->info = io;
-    i->outputDev = new GFXOutputDev(device_config);
+
+    if(0) {
+       BitmapOutputDev*outputDev = new BitmapOutputDev(io, i->doc);
+       i->outputDev = (CommonOutputDev*)outputDev;
+    } else {
+       GFXOutputDev*outputDev = new GFXOutputDev(io, i->doc);
+       i->outputDev = (CommonOutputDev*)outputDev;
+    }
+
+    /* pass global parameters to PDF driver*/
+    parameter_t*p = device_config;
+    while(p) {
+       i->outputDev->setParameter(p->name, p->value);
+       p = p->next;
+    }
 
     pdf_doc->get = 0;
     pdf_doc->destroy = pdf_doc_destroy;
 
     pdf_doc->get = 0;
     pdf_doc->destroy = pdf_doc_destroy;
@@ -401,5 +422,12 @@ gfxsource_t*gfxsource_pdf_create()
     memset(src, 0, sizeof(gfxsource_t));
     src->set_parameter = pdf_set_parameter;
     src->open = pdf_open;
     memset(src, 0, sizeof(gfxsource_t));
     src->set_parameter = pdf_set_parameter;
     src->open = pdf_open;
+
+    if(!globalParams) {
+        globalParams = new GFXGlobalParams();
+       //globalparams_count++;
+    }
+    
+
     return src;
 }
     return src;
 }
index 22e2177..68e1b93 100644 (file)
@@ -182,8 +182,11 @@ ${name}/lib/devices/ops.c \
 ${name}/lib/devices/ops.h \
 ${name}/lib/pdf/GFXOutputDev.h \
 ${name}/lib/pdf/GFXOutputDev.cc \
 ${name}/lib/devices/ops.h \
 ${name}/lib/pdf/GFXOutputDev.h \
 ${name}/lib/pdf/GFXOutputDev.cc \
+${name}/lib/pdf/BitmapOutputDev.h \
+${name}/lib/pdf/BitmapOutputDev.cc \
 ${name}/lib/pdf/InfoOutputDev.h \
 ${name}/lib/pdf/InfoOutputDev.cc \
 ${name}/lib/pdf/InfoOutputDev.h \
 ${name}/lib/pdf/InfoOutputDev.cc \
+${name}/lib/pdf/CommonOutputDev.h \
 ${name}/lib/pdf/fonts.c \
 ${name}/lib/pdf/fonts.h \
 ${name}/lib/pdf/pdf.cc \
 ${name}/lib/pdf/fonts.c \
 ${name}/lib/pdf/fonts.h \
 ${name}/lib/pdf/pdf.cc \