1 //======================================================================== 2 // 3 // SplashOutputDev.h 4 // 5 // Copyright 2003 Glyph & Cog, LLC 6 // 7 //======================================================================== 8 9 #ifndef SPLASHOUTPUTDEV_H 10 #define SPLASHOUTPUTDEV_H 11 12 #include <aconf.h> 13 14 #ifdef USE_GCC_PRAGMAS 15 #pragma interface 16 #endif 17 18 #include "gtypes.h" 19 #include "SplashTypes.h" 20 #include "config.h" 21 #include "OutputDev.h" 22 #include "GfxState.h" 23 24 class Gfx8BitFont; 25 class SplashBitmap; 26 class Splash; 27 class SplashPath; 28 class SplashPattern; 29 class SplashFontEngine; 30 class SplashFont; 31 class T3FontCache; 32 struct T3FontCacheTag; 33 struct T3GlyphStack; 34 struct SplashTransparencyGroup; 35 36 //------------------------------------------------------------------------ 37 38 // number of Type 3 fonts to cache 39 #define splashOutT3FontCacheSize 8 40 41 //------------------------------------------------------------------------ 42 // SplashOutputDev 43 //------------------------------------------------------------------------ 44 45 class SplashOutputDev: public OutputDev { 46 public: 47 48 // Constructor. 49 SplashOutputDev(SplashColorMode colorModeA, int bitmapRowPadA, 50 GBool reverseVideoA, SplashColorPtr paperColorA, 51 GBool bitmapTopDownA = gTrue, 52 GBool allowAntialiasA = gTrue); 53 54 // Destructor. 55 virtual ~SplashOutputDev(); 56 57 //----- get info about output device 58 59 // Does this device use upside-down coordinates? 60 // (Upside-down means (0,0) is the top left corner of the page.) upsideDown()61 virtual GBool upsideDown() { return bitmapTopDown ^ bitmapUpsideDown; } 62 63 // Does this device use drawChar() or drawString()? useDrawChar()64 virtual GBool useDrawChar() { return gTrue; } 65 66 // Does this device use tilingPatternFill()? If this returns false, 67 // tiling pattern fills will be reduced to a series of other drawing 68 // operations. useTilingPatternFill()69 virtual GBool useTilingPatternFill() { return gTrue; } 70 71 // Does this device use beginType3Char/endType3Char? Otherwise, 72 // text in Type 3 fonts will be drawn with drawChar/drawString. interpretType3Chars()73 virtual GBool interpretType3Chars() { return gTrue; } 74 75 76 //----- initialization and control 77 78 // Start a page. 79 virtual void startPage(int pageNum, GfxState *state); 80 81 // End a page. 82 virtual void endPage(); 83 84 //----- save/restore graphics state 85 virtual void saveState(GfxState *state); 86 virtual void restoreState(GfxState *state); 87 88 //----- update graphics state 89 virtual void updateAll(GfxState *state); 90 virtual void updateCTM(GfxState *state, double m11, double m12, 91 double m21, double m22, double m31, double m32); 92 virtual void updateLineDash(GfxState *state); 93 virtual void updateFlatness(GfxState *state); 94 virtual void updateLineJoin(GfxState *state); 95 virtual void updateLineCap(GfxState *state); 96 virtual void updateMiterLimit(GfxState *state); 97 virtual void updateLineWidth(GfxState *state); 98 virtual void updateStrokeAdjust(GfxState *state); 99 virtual void updateFillColor(GfxState *state); 100 virtual void updateStrokeColor(GfxState *state); 101 virtual void updateBlendMode(GfxState *state); 102 virtual void updateFillOpacity(GfxState *state); 103 virtual void updateStrokeOpacity(GfxState *state); 104 virtual void updateTransfer(GfxState *state); 105 106 //----- update text state 107 virtual void updateFont(GfxState *state); 108 109 //----- path painting 110 virtual void stroke(GfxState *state); 111 virtual void fill(GfxState *state); 112 virtual void eoFill(GfxState *state); 113 virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *strRef, 114 int paintType, Dict *resDict, 115 double *mat, double *bbox, 116 int x0, int y0, int x1, int y1, 117 double xStep, double yStep); 118 119 //----- path clipping 120 virtual void clip(GfxState *state); 121 virtual void eoClip(GfxState *state); 122 virtual void clipToStrokePath(GfxState *state); 123 124 //----- text drawing 125 virtual void drawChar(GfxState *state, double x, double y, 126 double dx, double dy, 127 double originX, double originY, 128 CharCode code, int nBytes, Unicode *u, int uLen); 129 virtual GBool beginType3Char(GfxState *state, double x, double y, 130 double dx, double dy, 131 CharCode code, Unicode *u, int uLen); 132 virtual void endType3Char(GfxState *state); 133 virtual void endTextObject(GfxState *state); 134 135 //----- image drawing 136 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, 137 int width, int height, GBool invert, 138 GBool inlineImg, GBool interpolate); 139 virtual void setSoftMaskFromImageMask(GfxState *state, 140 Object *ref, Stream *str, 141 int width, int height, GBool invert, 142 GBool inlineImg, GBool interpolate); 143 virtual void drawImage(GfxState *state, Object *ref, Stream *str, 144 int width, int height, GfxImageColorMap *colorMap, 145 int *maskColors, GBool inlineImg, GBool interpolate); 146 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str, 147 int width, int height, 148 GfxImageColorMap *colorMap, 149 Stream *maskStr, int maskWidth, int maskHeight, 150 GBool maskInvert, GBool interpolate); 151 virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, 152 int width, int height, 153 GfxImageColorMap *colorMap, 154 Stream *maskStr, 155 int maskWidth, int maskHeight, 156 GfxImageColorMap *maskColorMap, 157 GBool interpolate); 158 159 //----- Type 3 font operators 160 virtual void type3D0(GfxState *state, double wx, double wy); 161 virtual void type3D1(GfxState *state, double wx, double wy, 162 double llx, double lly, double urx, double ury); 163 164 //----- transparency groups and soft masks 165 virtual void beginTransparencyGroup(GfxState *state, double *bbox, 166 GfxColorSpace *blendingColorSpace, 167 GBool isolated, GBool knockout, 168 GBool forSoftMask); 169 virtual void endTransparencyGroup(GfxState *state); 170 virtual void paintTransparencyGroup(GfxState *state, double *bbox); 171 virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, 172 Function *transferFunc, GfxColor *backdropColor); 173 virtual void clearSoftMask(GfxState *state); 174 175 //----- special access 176 177 // Called to indicate that a new PDF document has been loaded. 178 void startDoc(XRef *xrefA); 179 180 void setPaperColor(SplashColorPtr paperColorA); 181 isReverseVideo()182 GBool isReverseVideo() { return reverseVideo; } setReverseVideo(GBool reverseVideoA)183 void setReverseVideo(GBool reverseVideoA) { reverseVideo = reverseVideoA; } 184 185 // Get the bitmap and its size. getBitmap()186 SplashBitmap *getBitmap() { return bitmap; } 187 int getBitmapWidth(); 188 int getBitmapHeight(); 189 190 // Returns the last rasterized bitmap, transferring ownership to the 191 // caller. 192 SplashBitmap *takeBitmap(); 193 194 // Set this flag to true to generate an upside-down bitmap (useful 195 // for Windows BMP files). setBitmapUpsideDown(GBool f)196 void setBitmapUpsideDown(GBool f) { bitmapUpsideDown = f; } 197 198 // Setting this to true disables the final composite (with the 199 // opaque paper color), resulting in transparent output. setNoComposite(GBool f)200 void setNoComposite(GBool f) { noComposite = f; } 201 202 // Get the Splash object. getSplash()203 Splash *getSplash() { return splash; } 204 205 // Get the modified region. 206 void getModRegion(int *xMin, int *yMin, int *xMax, int *yMax); 207 208 // Clear the modified region. 209 void clearModRegion(); 210 211 // Set the Splash fill color. 212 void setFillColor(int r, int g, int b); 213 214 // Get a font object for a Base-14 font, using the Latin-1 encoding. 215 SplashFont *getFont(GString *name, SplashCoord *textMatA); 216 getCurrentFont()217 SplashFont *getCurrentFont() { return font; } 218 219 // If <skipTextA> is true, don't draw horizontal text. 220 // If <skipRotatedTextA> is true, don't draw rotated (non-horizontal) text. setSkipText(GBool skipHorizTextA,GBool skipRotatedTextA)221 void setSkipText(GBool skipHorizTextA, GBool skipRotatedTextA) 222 { skipHorizText = skipHorizTextA; skipRotatedText = skipRotatedTextA; } 223 getNestCount()224 int getNestCount() { return nestCount; } 225 226 227 #if 1 //~tmp: turn off anti-aliasing temporarily 228 virtual void setInShading(GBool sh); 229 #endif 230 231 private: 232 233 void setupScreenParams(double hDPI, double vDPI); 234 SplashPattern *getColor(GfxGray gray); 235 SplashPattern *getColor(GfxRGB *rgb); 236 #if SPLASH_CMYK 237 SplashPattern *getColor(GfxCMYK *cmyk); 238 #endif 239 void setOverprintMask(GfxColorSpace *colorSpace, GBool overprintFlag, 240 int overprintMode, GfxColor *singleColor); 241 SplashPath *convertPath(GfxState *state, GfxPath *path, 242 GBool dropEmptySubpaths); 243 void doUpdateFont(GfxState *state); 244 void drawType3Glyph(GfxState *state, T3FontCache *t3Font, 245 T3FontCacheTag *tag, Guchar *data); 246 static GBool imageMaskSrc(void *data, SplashColorPtr line); 247 static GBool imageSrc(void *data, SplashColorPtr colorLine, 248 Guchar *alphaLine); 249 static GBool alphaImageSrc(void *data, SplashColorPtr line, 250 Guchar *alphaLine); 251 static GBool maskedImageSrc(void *data, SplashColorPtr line, 252 Guchar *alphaLine); 253 void reduceImageResolution(Stream *str, double *mat, 254 int *width, int *height); 255 void clearMaskRegion(GfxState *state, 256 Splash *maskSplash, 257 double xMin, double yMin, 258 double xMax, double yMax); 259 260 SplashColorMode colorMode; 261 int bitmapRowPad; 262 GBool bitmapTopDown; 263 GBool bitmapUpsideDown; 264 GBool noComposite; 265 GBool allowAntialias; 266 GBool vectorAntialias; 267 GBool reverseVideo; // reverse video mode 268 SplashColor paperColor; // paper color 269 SplashScreenParams screenParams; 270 GBool skipHorizText; 271 GBool skipRotatedText; 272 273 XRef *xref; // xref table for current document 274 275 SplashBitmap *bitmap; 276 Splash *splash; 277 SplashFontEngine *fontEngine; 278 279 T3FontCache * // Type 3 font cache 280 t3FontCache[splashOutT3FontCacheSize]; 281 int nT3Fonts; // number of valid entries in t3FontCache 282 T3GlyphStack *t3GlyphStack; // Type 3 glyph context stack 283 284 SplashFont *font; // current font 285 GBool needFontUpdate; // set when the font needs to be updated 286 SplashPath *textClipPath; // clipping path built with text object 287 288 SplashTransparencyGroup * // transparency group stack 289 transpGroupStack; 290 291 int nestCount; 292 }; 293 294 #endif 295