root/middleware-offline/trunk/_src/eidmw/pteid-poppler/poppler/SplashOutputDev.h @ 226

Revision 226, 14.5 KB (checked in by vsilva, 8 years ago)

Improve PDF native Signature

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