1 //======================================================================== 2 // 3 // SplashOutputDev.h 4 // 5 // Copyright 2003 Glyph & Cog, LLC 6 // 7 //======================================================================== 8 9 //======================================================================== 10 // 11 // Modified under the Poppler project - http://poppler.freedesktop.org 12 // 13 // All changes made under the Poppler project to this file are licensed 14 // under GPL version 2 or later 15 // 16 // Copyright (C) 2005 Takashi Iwai <tiwai@suse.de> 17 // Copyright (C) 2009-2014 Thomas Freitag <Thomas.Freitag@alfa.de> 18 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org> 19 // Copyright (C) 2010 Christian Feuers�nger <cfeuersaenger@googlemail.com> 20 // Copyright (C) 2011 Andreas Hartmetz <ahartmetz@gmail.com> 21 // Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com> 22 // Copyright (C) 2011 Adrian Johnson <ajohnson@redneon.com> 23 // Copyright (C) 2012, 2015 Albert Astals Cid <aacid@kde.org> 24 // Copyright (C) 2015 William Bader <williambader@hotmail.com> 25 // 26 // To see a description of the changes please see the Changelog file that 27 // came with your tarball or type make ChangeLog if you are building from git 28 // 29 //======================================================================== 30 31 #ifndef SPLASHOUTPUTDEV_H 32 #define SPLASHOUTPUTDEV_H 33 34 #ifdef USE_GCC_PRAGMAS 35 #pragma interface 36 #endif 37 38 #include "goo/gtypes.h" 39 #include "splash/SplashTypes.h" 40 #include "splash/SplashPattern.h" 41 #include "poppler-config.h" 42 #include "OutputDev.h" 43 #include "GfxState.h" 44 #include "GlobalParams.h" 45 46 class PDFDoc; 47 class Gfx8BitFont; 48 class SplashBitmap; 49 class Splash; 50 class SplashPath; 51 class SplashFontEngine; 52 class SplashFont; 53 class T3FontCache; 54 struct T3FontCacheTag; 55 struct T3GlyphStack; 56 struct SplashTransparencyGroup; 57 58 //------------------------------------------------------------------------ 59 // Splash dynamic pattern 60 //------------------------------------------------------------------------ 61 62 class SplashUnivariatePattern: public SplashPattern { 63 public: 64 65 SplashUnivariatePattern(SplashColorMode colorMode, GfxState *state, GfxUnivariateShading *shading); 66 67 virtual ~SplashUnivariatePattern(); 68 69 virtual GBool getColor(int x, int y, SplashColorPtr c); 70 71 virtual GBool testPosition(int x, int y); 72 isStatic()73 virtual GBool isStatic() { return gFalse; } 74 75 virtual GBool getParameter(double xs, double ys, double *t) = 0; 76 getShading()77 virtual GfxUnivariateShading *getShading() { return shading; } 78 isCMYK()79 virtual GBool isCMYK() { return gfxMode == csDeviceCMYK; } 80 81 protected: 82 Matrix ictm; 83 double t0, t1, dt; 84 GfxUnivariateShading *shading; 85 GfxState *state; 86 SplashColorMode colorMode; 87 GfxColorSpaceMode gfxMode; 88 }; 89 90 class SplashAxialPattern: public SplashUnivariatePattern { 91 public: 92 93 SplashAxialPattern(SplashColorMode colorMode, GfxState *state, GfxAxialShading *shading); 94 copy()95 virtual SplashPattern *copy() { return new SplashAxialPattern(colorMode, state, (GfxAxialShading *) shading); } 96 97 virtual ~SplashAxialPattern(); 98 99 virtual GBool getParameter(double xs, double ys, double *t); 100 101 private: 102 double x0, y0, x1, y1; 103 double dx, dy, mul; 104 }; 105 106 // see GfxState.h, GfxGouraudTriangleShading 107 class SplashGouraudPattern: public SplashGouraudColor { 108 public: 109 110 SplashGouraudPattern(GBool bDirectColorTranslation, GfxState *state, GfxGouraudTriangleShading *shading, SplashColorMode mode); 111 copy()112 virtual SplashPattern *copy() { return new SplashGouraudPattern(bDirectColorTranslation, state, shading, mode); } 113 114 virtual ~SplashGouraudPattern(); 115 getColor(int x,int y,SplashColorPtr c)116 virtual GBool getColor(int x, int y, SplashColorPtr c) { return gFalse; } 117 testPosition(int x,int y)118 virtual GBool testPosition(int x, int y) { return gFalse; } 119 isStatic()120 virtual GBool isStatic() { return gFalse; } 121 isCMYK()122 virtual GBool isCMYK() { return gfxMode == csDeviceCMYK; } 123 isParameterized()124 virtual GBool isParameterized() { return shading->isParameterized(); } getNTriangles()125 virtual int getNTriangles() { return shading->getNTriangles(); } getTriangle(int i,double * x0,double * y0,double * color0,double * x1,double * y1,double * color1,double * x2,double * y2,double * color2)126 virtual void getTriangle(int i, double *x0, double *y0, double *color0, 127 double *x1, double *y1, double *color1, 128 double *x2, double *y2, double *color2) 129 { return shading->getTriangle(i, x0, y0, color0, x1, y1, color1, x2, y2, color2); } 130 131 virtual void getParameterizedColor(double t, SplashColorMode mode, SplashColorPtr c); 132 133 private: 134 GfxGouraudTriangleShading *shading; 135 GfxState *state; 136 GBool bDirectColorTranslation; 137 SplashColorMode mode; 138 GfxColorSpaceMode gfxMode; 139 }; 140 141 // see GfxState.h, GfxRadialShading 142 class SplashRadialPattern: public SplashUnivariatePattern { 143 public: 144 145 SplashRadialPattern(SplashColorMode colorMode, GfxState *state, GfxRadialShading *shading); 146 copy()147 virtual SplashPattern *copy() { return new SplashRadialPattern(colorMode, state, (GfxRadialShading *) shading); } 148 149 virtual ~SplashRadialPattern(); 150 151 virtual GBool getParameter(double xs, double ys, double *t); 152 153 private: 154 double x0, y0, r0, dx, dy, dr; 155 double a, inva; 156 }; 157 158 //------------------------------------------------------------------------ 159 160 // number of Type 3 fonts to cache 161 #define splashOutT3FontCacheSize 8 162 163 //------------------------------------------------------------------------ 164 // SplashOutputDev 165 //------------------------------------------------------------------------ 166 167 class SplashOutputDev: public OutputDev { 168 public: 169 170 // Constructor. 171 SplashOutputDev(SplashColorMode colorModeA, int bitmapRowPadA, 172 GBool reverseVideoA, SplashColorPtr paperColorA, 173 GBool bitmapTopDownA = gTrue, 174 SplashThinLineMode thinLineMode = splashThinLineDefault, 175 GBool overprintPreviewA = globalParams->getOverprintPreview()); 176 177 // Destructor. 178 virtual ~SplashOutputDev(); 179 180 //----- get info about output device 181 182 // Does this device use tilingPatternFill()? If this returns false, 183 // tiling pattern fills will be reduced to a series of other drawing 184 // operations. useTilingPatternFill()185 virtual GBool useTilingPatternFill() { return gTrue; } 186 187 // Does this device use functionShadedFill(), axialShadedFill(), and 188 // radialShadedFill()? If this returns false, these shaded fills 189 // will be reduced to a series of other drawing operations. useShadedFills(int type)190 virtual GBool useShadedFills(int type) 191 { return (type >= 2 && type <= 5) ? gTrue : gFalse; } 192 193 // Does this device use upside-down coordinates? 194 // (Upside-down means (0,0) is the top left corner of the page.) upsideDown()195 virtual GBool upsideDown() { return bitmapTopDown ^ bitmapUpsideDown; } 196 197 // Does this device use drawChar() or drawString()? useDrawChar()198 virtual GBool useDrawChar() { return gTrue; } 199 200 // Does this device use beginType3Char/endType3Char? Otherwise, 201 // text in Type 3 fonts will be drawn with drawChar/drawString. interpretType3Chars()202 virtual GBool interpretType3Chars() { return gTrue; } 203 204 //----- initialization and control 205 206 // Start a page. 207 virtual void startPage(int pageNum, GfxState *state, XRef *xref); 208 209 // End a page. 210 virtual void endPage(); 211 212 //----- save/restore graphics state 213 virtual void saveState(GfxState *state); 214 virtual void restoreState(GfxState *state); 215 216 //----- update graphics state 217 virtual void updateAll(GfxState *state); 218 virtual void updateCTM(GfxState *state, double m11, double m12, 219 double m21, double m22, double m31, double m32); 220 virtual void updateLineDash(GfxState *state); 221 virtual void updateFlatness(GfxState *state); 222 virtual void updateLineJoin(GfxState *state); 223 virtual void updateLineCap(GfxState *state); 224 virtual void updateMiterLimit(GfxState *state); 225 virtual void updateLineWidth(GfxState *state); 226 virtual void updateStrokeAdjust(GfxState *state); 227 virtual void updateFillColorSpace(GfxState *state); 228 virtual void updateStrokeColorSpace(GfxState *state); 229 virtual void updateFillColor(GfxState *state); 230 virtual void updateStrokeColor(GfxState *state); 231 virtual void updateBlendMode(GfxState *state); 232 virtual void updateFillOpacity(GfxState *state); 233 virtual void updateStrokeOpacity(GfxState *state); 234 virtual void updateFillOverprint(GfxState *state); 235 virtual void updateStrokeOverprint(GfxState *state); 236 virtual void updateOverprintMode(GfxState *state); 237 virtual void updateTransfer(GfxState *state); 238 239 //----- update text state 240 virtual void updateFont(GfxState *state); 241 242 //----- path painting 243 virtual void stroke(GfxState *state); 244 virtual void fill(GfxState *state); 245 virtual void eoFill(GfxState *state); 246 virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *catalog, Object *str, 247 double *pmat, int paintType, int tilingType, Dict *resDict, 248 double *mat, double *bbox, 249 int x0, int y0, int x1, int y1, 250 double xStep, double yStep); 251 virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax); 252 virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading, double tMin, double tMax); 253 virtual GBool gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading); 254 255 //----- path clipping 256 virtual void clip(GfxState *state); 257 virtual void eoClip(GfxState *state); 258 virtual void clipToStrokePath(GfxState *state); 259 260 //----- text drawing 261 virtual void drawChar(GfxState *state, double x, double y, 262 double dx, double dy, 263 double originX, double originY, 264 CharCode code, int nBytes, Unicode *u, int uLen); 265 virtual GBool beginType3Char(GfxState *state, double x, double y, 266 double dx, double dy, 267 CharCode code, Unicode *u, int uLen); 268 virtual void endType3Char(GfxState *state); 269 virtual void beginTextObject(GfxState *state); 270 virtual void endTextObject(GfxState *state); 271 272 //----- image drawing 273 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, 274 int width, int height, GBool invert, 275 GBool interpolate, GBool inlineImg); 276 virtual void setSoftMaskFromImageMask(GfxState *state, 277 Object *ref, Stream *str, 278 int width, int height, GBool invert, 279 GBool inlineImg, double *baseMatrix); 280 virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix); 281 virtual void drawImage(GfxState *state, Object *ref, Stream *str, 282 int width, int height, GfxImageColorMap *colorMap, 283 GBool interpolate, int *maskColors, GBool inlineImg); 284 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str, 285 int width, int height, 286 GfxImageColorMap *colorMap, 287 GBool interpolate, 288 Stream *maskStr, int maskWidth, int maskHeight, 289 GBool maskInvert, GBool maskInterpolate); 290 virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, 291 int width, int height, 292 GfxImageColorMap *colorMap, 293 GBool interpolate, 294 Stream *maskStr, 295 int maskWidth, int maskHeight, 296 GfxImageColorMap *maskColorMap, 297 GBool maskInterpolate); 298 299 //----- Type 3 font operators 300 virtual void type3D0(GfxState *state, double wx, double wy); 301 virtual void type3D1(GfxState *state, double wx, double wy, 302 double llx, double lly, double urx, double ury); 303 304 //----- transparency groups and soft masks 305 virtual GBool checkTransparencyGroup(GfxState *state, GBool knockout); 306 virtual void beginTransparencyGroup(GfxState *state, double *bbox, 307 GfxColorSpace *blendingColorSpace, 308 GBool isolated, GBool knockout, 309 GBool forSoftMask); 310 virtual void endTransparencyGroup(GfxState *state); 311 virtual void paintTransparencyGroup(GfxState *state, double *bbox); 312 virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, 313 Function *transferFunc, GfxColor *backdropColor); 314 virtual void clearSoftMask(GfxState *state); 315 316 //----- special access 317 318 // Called to indicate that a new PDF document has been loaded. 319 void startDoc(PDFDoc *docA); 320 321 void setPaperColor(SplashColorPtr paperColorA); 322 isReverseVideo()323 GBool isReverseVideo() { return reverseVideo; } setReverseVideo(GBool reverseVideoA)324 void setReverseVideo(GBool reverseVideoA) { reverseVideo = reverseVideoA; } 325 326 // Get the bitmap and its size. getBitmap()327 SplashBitmap *getBitmap() { return bitmap; } 328 int getBitmapWidth(); 329 int getBitmapHeight(); 330 331 // Returns the last rasterized bitmap, transferring ownership to the 332 // caller. 333 SplashBitmap *takeBitmap(); 334 335 // Set this flag to true to generate an upside-down bitmap (useful 336 // for Windows BMP files). setBitmapUpsideDown(GBool f)337 void setBitmapUpsideDown(GBool f) { bitmapUpsideDown = f; } 338 339 // Get the Splash object. getSplash()340 Splash *getSplash() { return splash; } 341 342 // Get the modified region. 343 void getModRegion(int *xMin, int *yMin, int *xMax, int *yMax); 344 345 // Clear the modified region. 346 void clearModRegion(); 347 getCurrentFont()348 SplashFont *getCurrentFont() { return font; } 349 350 // If <skipTextA> is true, don't draw horizontal text. 351 // If <skipRotatedTextA> is true, don't draw rotated (non-horizontal) text. setSkipText(GBool skipHorizTextA,GBool skipRotatedTextA)352 void setSkipText(GBool skipHorizTextA, GBool skipRotatedTextA) 353 { skipHorizText = skipHorizTextA; skipRotatedText = skipRotatedTextA; } 354 getNestCount()355 int getNestCount() { return nestCount; } 356 357 #if 1 //~tmp: turn off anti-aliasing temporarily 358 virtual GBool getVectorAntialias(); 359 virtual void setVectorAntialias(GBool vaa); 360 #endif 361 getFontAntialias()362 GBool getFontAntialias() { return fontAntialias; } setFontAntialias(GBool anti)363 void setFontAntialias(GBool anti) { fontAntialias = anti; } 364 365 void setFreeTypeHinting(GBool enable, GBool enableSlightHinting); 366 367 protected: 368 void doUpdateFont(GfxState *state); 369 370 private: 371 GBool univariateShadedFill(GfxState *state, SplashUnivariatePattern *pattern, double tMin, double tMax); 372 373 void setupScreenParams(double hDPI, double vDPI); 374 SplashPattern *getColor(GfxGray gray); 375 SplashPattern *getColor(GfxRGB *rgb); 376 #if SPLASH_CMYK 377 SplashPattern *getColor(GfxCMYK *cmyk); 378 SplashPattern *getColor(GfxColor *deviceN); 379 #endif 380 void setOverprintMask(GfxColorSpace *colorSpace, GBool overprintFlag, 381 int overprintMode, GfxColor *singleColor, GBool grayIndexed = gFalse); 382 SplashPath *convertPath(GfxState *state, GfxPath *path, 383 GBool dropEmptySubpaths); 384 void drawType3Glyph(GfxState *state, T3FontCache *t3Font, 385 T3FontCacheTag *tag, Guchar *data); 386 static GBool imageMaskSrc(void *data, SplashColorPtr line); 387 static GBool imageSrc(void *data, SplashColorPtr colorLine, 388 Guchar *alphaLine); 389 static GBool alphaImageSrc(void *data, SplashColorPtr line, 390 Guchar *alphaLine); 391 static GBool maskedImageSrc(void *data, SplashColorPtr line, 392 Guchar *alphaLine); 393 static GBool tilingBitmapSrc(void *data, SplashColorPtr line, 394 Guchar *alphaLine); 395 396 GBool keepAlphaChannel; // don't fill with paper color, keep alpha channel 397 398 SplashColorMode colorMode; 399 int bitmapRowPad; 400 GBool bitmapTopDown; 401 GBool bitmapUpsideDown; 402 GBool fontAntialias; 403 GBool vectorAntialias; 404 GBool overprintPreview; 405 GBool enableFreeTypeHinting; 406 GBool enableSlightHinting; 407 GBool reverseVideo; // reverse video mode 408 SplashColor paperColor; // paper color 409 SplashScreenParams screenParams; 410 GBool skipHorizText; 411 GBool skipRotatedText; 412 413 PDFDoc *doc; // the current document 414 XRef *xref; // the xref of the current document 415 416 SplashBitmap *bitmap; 417 Splash *splash; 418 SplashFontEngine *fontEngine; 419 420 T3FontCache * // Type 3 font cache 421 t3FontCache[splashOutT3FontCacheSize]; 422 int nT3Fonts; // number of valid entries in t3FontCache 423 T3GlyphStack *t3GlyphStack; // Type 3 glyph context stack 424 GBool haveT3Dx; // set after seeing a d0/d1 operator 425 426 SplashFont *font; // current font 427 GBool needFontUpdate; // set when the font needs to be updated 428 SplashPath *textClipPath; // clipping path built with text object 429 430 SplashTransparencyGroup * // transparency group stack 431 transpGroupStack; 432 SplashBitmap *maskBitmap; // for image masks in pattern colorspace 433 int nestCount; 434 }; 435 436 #endif 437