Coverage Report

Created: 2026-03-15 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/xpdf/SplashOutputDev.h
Line
Count
Source
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
#include "gtypes.h"
15
#include "SplashTypes.h"
16
#include "config.h"
17
#include "OutputDev.h"
18
#include "GfxState.h"
19
20
class Gfx8BitFont;
21
class SplashBitmap;
22
class SplashBitmapMemCache;
23
class Splash;
24
class SplashPath;
25
class SplashPattern;
26
class SplashFontEngine;
27
class SplashFont;
28
class T3FontCache;
29
struct T3FontCacheTag;
30
struct T3GlyphStack;
31
struct SplashTransparencyGroup;
32
33
//------------------------------------------------------------------------
34
35
// number of Type 3 fonts to cache
36
12.0k
#define splashOutT3FontCacheSize 8
37
38
//------------------------------------------------------------------------
39
// SplashOutputDev
40
//------------------------------------------------------------------------
41
42
class SplashOutputDev: public OutputDev {
43
public:
44
45
  // Constructor.
46
  SplashOutputDev(SplashColorMode colorModeA, int bitmapRowPadA,
47
      GBool reverseVideoA, SplashColorPtr paperColorA,
48
      GBool bitmapTopDownA = gTrue,
49
      GBool allowAntialiasA = gTrue);
50
51
52
  // Destructor.
53
  virtual ~SplashOutputDev();
54
55
  //----- get info about output device
56
57
  // Does this device use upside-down coordinates?
58
  // (Upside-down means (0,0) is the top left corner of the page.)
59
353k
  virtual GBool upsideDown() { return bitmapTopDown ^ bitmapUpsideDown; }
60
61
  // Does this device use drawChar() or drawString()?
62
1.77M
  virtual GBool useDrawChar() { return gTrue; }
63
64
  // Does this device use tilingPatternFill()?  If this returns false,
65
  // tiling pattern fills will be reduced to a series of other drawing
66
  // operations.
67
434
  virtual GBool useTilingPatternFill() { return gTrue; }
68
69
  // Does this device use beginType3Char/endType3Char?  Otherwise,
70
  // text in Type 3 fonts will be drawn with drawChar/drawString.
71
20.5k
  virtual GBool interpretType3Chars() { return gTrue; }
72
73
74
75
  //----- initialization and control
76
77
  // Start a page.
78
  virtual void startPage(int pageNum, GfxState *state);
79
80
  // End a page.
81
  virtual void endPage();
82
83
  //----- save/restore graphics state
84
  virtual void saveState(GfxState *state);
85
  virtual void restoreState(GfxState *state);
86
87
  //----- update graphics state
88
  virtual void updateAll(GfxState *state);
89
  virtual void updateCTM(GfxState *state, double m11, double m12,
90
       double m21, double m22, double m31, double m32);
91
  virtual void updateLineDash(GfxState *state);
92
  virtual void updateFlatness(GfxState *state);
93
  virtual void updateLineJoin(GfxState *state);
94
  virtual void updateLineCap(GfxState *state);
95
  virtual void updateMiterLimit(GfxState *state);
96
  virtual void updateLineWidth(GfxState *state);
97
  virtual void updateStrokeAdjust(GfxState *state);
98
  virtual void updateFillColor(GfxState *state);
99
  virtual void updateStrokeColor(GfxState *state);
100
  virtual void updateBlendMode(GfxState *state);
101
  virtual void updateFillOpacity(GfxState *state);
102
  virtual void updateStrokeOpacity(GfxState *state);
103
  virtual void updateRenderingIntent(GfxState *state);
104
  virtual void updateTransfer(GfxState *state);
105
  virtual void updateAlphaIsShape(GfxState *state);
106
107
  //----- update text state
108
  virtual void updateFont(GfxState *state);
109
110
  //----- path painting
111
  virtual void stroke(GfxState *state);
112
  virtual void fill(GfxState *state);
113
  virtual void eoFill(GfxState *state);
114
  virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *strRef,
115
         int paintType, int tilingType, Dict *resDict,
116
         double *mat, double *bbox,
117
         int x0, int y0, int x1, int y1,
118
         double xStep, double yStep);
119
  virtual GBool shadedFill(GfxState *state, GfxShading *shading);
120
121
  //----- path clipping
122
  virtual void clip(GfxState *state);
123
  virtual void eoClip(GfxState *state);
124
  virtual void clipToStrokePath(GfxState *state);
125
126
  //----- text drawing
127
  virtual void drawChar(GfxState *state, double x, double y,
128
      double dx, double dy,
129
      double originX, double originY,
130
      CharCode code, int nBytes, Unicode *u, int uLen,
131
      GBool fill, GBool stroke, GBool makePath);
132
  virtual void fillTextPath(GfxState *state);
133
  virtual void strokeTextPath(GfxState *state);
134
  virtual void clipToTextPath(GfxState *state);
135
  virtual void clipToTextStrokePath(GfxState *state);
136
  virtual void clearTextPath(GfxState *state);
137
  virtual void addTextPathToSavedClipPath(GfxState *state);
138
  virtual void clipToSavedClipPath(GfxState *state);
139
  virtual GBool beginType3Char(GfxState *state, double x, double y,
140
             double dx, double dy,
141
             CharCode code, Unicode *u, int uLen);
142
  virtual void endType3Char(GfxState *state);
143
  virtual void endTextObject(GfxState *state);
144
145
  //----- image drawing
146
  virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
147
           int width, int height, GBool invert,
148
           GBool inlineImg, GBool interpolate);
149
  virtual void setSoftMaskFromImageMask(GfxState *state,
150
          Object *ref, Stream *str,
151
          int width, int height, GBool invert,
152
          GBool inlineImg, GBool interpolate);
153
  virtual void drawImage(GfxState *state, Object *ref, Stream *str,
154
       int width, int height, GfxImageColorMap *colorMap,
155
       int *maskColors, GBool inlineImg, GBool interpolate);
156
  virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
157
             int width, int height,
158
             GfxImageColorMap *colorMap,
159
             Object *maskRef, Stream *maskStr,
160
             int maskWidth, int maskHeight,
161
             GBool maskInvert, GBool interpolate);
162
  virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
163
           int width, int height,
164
           GfxImageColorMap *colorMap,
165
           Object *maskRef, Stream *maskStr,
166
           int maskWidth, int maskHeight,
167
           GfxImageColorMap *maskColorMap,
168
           double *matte, GBool interpolate);
169
170
  //----- Type 3 font operators
171
  virtual void type3D0(GfxState *state, double wx, double wy);
172
  virtual void type3D1(GfxState *state, double wx, double wy,
173
           double llx, double lly, double urx, double ury);
174
175
  //----- transparency groups and soft masks
176
  virtual GBool beginTransparencyGroup(GfxState *state, double *bbox,
177
               GfxColorSpace *blendingColorSpace,
178
               GBool isolated, GBool knockout,
179
               GBool forSoftMask);
180
  virtual void endTransparencyGroup(GfxState *state);
181
  virtual void paintTransparencyGroup(GfxState *state, double *bbox);
182
  virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha,
183
         Function *transferFunc, GfxColor *backdropColor);
184
  virtual void clearSoftMask(GfxState *state);
185
186
  //----- special access
187
188
  // Called to indicate that a new PDF document has been loaded.
189
  void startDoc(XRef *xrefA);
190
191
  void setStartPageCallback(void (*cbk)(void *data), void *data)
192
0
    { startPageCbk = cbk; startPageCbkData = data; }
193
 
194
  void setPaperColor(SplashColorPtr paperColorA);
195
196
0
  GBool isReverseVideo() { return reverseVideo; }
197
0
  void setReverseVideo(GBool reverseVideoA) { reverseVideo = reverseVideoA; }
198
199
  // Get the bitmap and its size.
200
12.8k
  SplashBitmap *getBitmap() { return bitmap; }
201
  int getBitmapWidth();
202
  int getBitmapHeight();
203
204
  // Returns the last rasterized bitmap, transferring ownership to the
205
  // caller.
206
  SplashBitmap *takeBitmap();
207
208
  // Set this flag to true to generate an upside-down bitmap (useful
209
  // for Windows BMP files).
210
0
  void setBitmapUpsideDown(GBool f) { bitmapUpsideDown = f; }
211
212
  // Setting this to true disables the final composite (with the
213
  // opaque paper color), resulting in transparent output.
214
12.8k
  void setNoComposite(GBool f) { noComposite = f; }
215
216
  // Get the Splash object.
217
0
  Splash *getSplash() { return splash; }
218
219
  // Get the modified region.
220
  void getModRegion(int *xMin, int *yMin, int *xMax, int *yMax);
221
222
  // Clear the modified region.
223
  void clearModRegion();
224
225
  // Set the Splash fill color.
226
  void setFillColor(int r, int g, int b);
227
228
  // Get a font object for a Base-14 font, using the Latin-1 encoding.
229
  SplashFont *getFont(GString *name, SplashCoord *textMatA);
230
231
0
  SplashFont *getCurrentFont() { return font; }
232
233
  // If <skipTextA> is true, don't draw horizontal text.
234
  // If <skipRotatedTextA> is true, don't draw rotated (non-horizontal) text.
235
  void setSkipText(GBool skipHorizTextA, GBool skipRotatedTextA)
236
0
    { skipHorizText = skipHorizTextA; skipRotatedText = skipRotatedTextA; }
237
238
0
  int getNestCount() { return nestCount; }
239
240
241
  // Get the screen parameters.
242
0
  SplashScreenParams *getScreenParams() { return &screenParams; }
243
244
0
  SplashBitmapMemCache *getBitmapMemCache() { return bitmapMemCache; }
245
246
private:
247
248
  void setupScreenParams(double hDPI, double vDPI);
249
  SplashPattern *getColor(GfxGray gray);
250
  SplashPattern *getColor(GfxRGB *rgb);
251
#if SPLASH_CMYK
252
  SplashPattern *getColor(GfxCMYK *cmyk);
253
#endif
254
  void getColor(GfxGray gray, SplashColorPtr color);
255
  void getColor(GfxRGB *rgb, SplashColorPtr color);
256
#if SPLASH_CMYK
257
  void getColor(GfxCMYK *cmyk, SplashColorPtr color);
258
#endif
259
  void setOverprintMask(GfxState *state, GfxColorSpace *colorSpace,
260
      GBool overprintFlag, int overprintMode,
261
      GfxColor *singleColor);
262
  SplashPath *convertPath(GfxState *state, GfxPath *path,
263
        GBool dropEmptySubpaths);
264
  void doUpdateFont(GfxState *state);
265
  void drawType3Glyph(GfxState *state, T3FontCache *t3Font,
266
          T3FontCacheTag *tag, Guchar *data);
267
  static GBool imageMaskSrc(void *data, Guchar *line);
268
  static GBool imageSrc(void *data, SplashColorPtr colorLine,
269
      Guchar *alphaLine);
270
  static GBool imageLookup1Src(void *data, SplashColorPtr colorLine,
271
             Guchar *alphaLine);
272
  static GBool imageLookup2Src(void *data, SplashColorPtr colorLine,
273
             Guchar *alphaLine);
274
  static GBool alphaImageSrc(void *data, SplashColorPtr line,
275
           Guchar *alphaLine);
276
  static GBool alphaImageLookup1Src(void *data, SplashColorPtr line,
277
            Guchar *alphaLine);
278
  static GBool alphaImageLookup2Src(void *data, SplashColorPtr line,
279
            Guchar *alphaLine);
280
  static GBool maskedImageSrc(void *data, SplashColorPtr line,
281
            Guchar *alphaLine);
282
  static GBool maskedImageLookup1Src(void *data, SplashColorPtr line,
283
             Guchar *alphaLine);
284
  void drawMaskedImage8(GfxState *state, Object *ref,
285
      Stream *str, int width, int height,
286
      GfxImageColorMap *colorMap,
287
      Object *maskRef, Stream *maskStr,
288
      int maskWidth, int maskHeight,
289
      GBool maskInvert, GBool interpolate);
290
  static GBool softMaskMatteImageSrc(void *data,
291
             SplashColorPtr colorLine,
292
             Guchar *alphaLine);
293
  void drawSoftMaskedImage8(GfxState *state, Object *ref,
294
          Stream *str, int width, int height,
295
          GfxImageColorMap *colorMap,
296
          Object *maskRef, Stream *maskStr,
297
          int maskWidth, int maskHeight,
298
          GfxImageColorMap *maskColorMap,
299
          double *matte, GBool interpolate);
300
  void drawSoftMaskedMatteImage8(GfxState *state, Object *ref,
301
         Stream *str, int width, int height,
302
         GfxImageColorMap *colorMap,
303
         Object *maskRef, Stream *maskStr,
304
         int maskWidth, int maskHeight,
305
         GfxImageColorMap *maskColorMap,
306
         double *matte, GBool interpolate);
307
  SplashColorPtr buildColorMapLookupTable1Idx(GfxImageColorMap *colorMap,
308
                GfxState *state);
309
  SplashColorPtr buildColorMapLookupTable2Idx(GfxImageColorMap *colorMap,
310
                GfxState *state);
311
  GString *makeImageTag(Object *ref, GfxRenderingIntent ri,
312
      GfxColorSpace *colorSpace);
313
  void reduceImageResolution(Stream *str, double *mat,
314
           int *width, int *height);
315
  void clearMaskRegion(GfxState *state,
316
           Splash *maskSplash,
317
           double xMin, double yMin,
318
           double xMax, double yMax);
319
  void copyState(Splash *oldSplash, GBool copyColors);
320
321
  SplashColorMode colorMode;
322
  int bitmapRowPad;
323
  GBool bitmapTopDown;
324
  GBool bitmapUpsideDown;
325
  GBool noComposite;
326
  GBool allowAntialias;
327
  GBool vectorAntialias;
328
  GBool reverseVideo;   // reverse video mode
329
  GBool reverseVideoInvertImages;
330
  SplashColor paperColor; // paper color
331
  SplashScreenParams screenParams;
332
  GBool skipHorizText;
333
  GBool skipRotatedText;
334
335
  XRef *xref;     // xref table for current document
336
337
  SplashBitmap *bitmap;
338
  SplashBitmapMemCache *bitmapMemCache;
339
  Splash *splash;
340
  SplashFontEngine *fontEngine;
341
342
  T3FontCache *     // Type 3 font cache
343
    t3FontCache[splashOutT3FontCacheSize];
344
  int nT3Fonts;     // number of valid entries in t3FontCache
345
  T3GlyphStack *t3GlyphStack; // Type 3 glyph context stack
346
347
  Ref tileCacheRef;
348
  double tileCacheBaseMatrix[6];
349
  SplashBitmap *tileCacheBitmap;
350
  Guint *tileCacheOverprintMaskBitmap;
351
352
  SplashFont *font;   // current font
353
  GBool needFontUpdate;   // set when the font needs to be updated
354
  SplashPath *savedTextPath;  // path built for text string
355
  SplashPath *savedClipPath;  // clipping path built with text object
356
357
  SplashTransparencyGroup * // transparency group stack
358
    transpGroupStack;
359
360
  int nestCount;
361
362
  void (*startPageCbk)(void *data);
363
  void *startPageCbkData;
364
};
365
366
#endif