--- /dev/null
+/* 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);
+}
--- /dev/null
+/* 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
#include "GlobalParams.h"
#include "InfoOutputDev.h"
#include "GFXOutputDev.h"
+#include "BitmapOutputDev.h"
#include "../mem.h"
#include "pdf.h"
#define NO_ARGPARSER
PDFDoc*doc;
Object docinfo;
InfoOutputDev*info;
- GFXOutputDev*outputDev;
+ CommonOutputDev*outputDev;
pdf_page_info_t*pages;
} pdf_doc_internal_t;
typedef struct _dev_output_internal
{
- GFXOutputDev*outputDev;
+ CommonOutputDev*outputDev;
} dev_output_internal_t;
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;
return;
}
+ pi->outputDev->setDevice(dev);
if(pi->protect) {
- gfxdevice_t*dev = pi->outputDev->device;
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->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;
- pi->outputDev->setDevice(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)
{
- 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;
- 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++;
+
+ pi->outputDev->setMove((int)x,(int)y);
pi->outputDev->setClip((int)x1,(int)y1,(int)x2,(int)y2);
render2(page, output);
- pi->outputDev->setDevice(0);
}
static int globalparams_count=0;
{
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;
global_page_range = 0;
}
- globalparams_count--;
+ /*globalparams_count--;
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;
- GFXOutputDev*o = i->outputDev;
+ CommonOutputDev*o = i->outputDev;
if(!strcmp(name, "pagemap")) {
int pdfpage=0, outputpage=0;
sscanf(value,"%d:%d", &pdfpage, &outputpage);
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);
- }
+ }
}
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));
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;
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;
}