beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / Gfx.h
bloba82f9f4af242efafb3e77f35d97e8fcc67eb4568
1 //========================================================================
2 //
3 // Gfx.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
17 // Copyright (C) 2007 Iñigo Martínez <inigomartinez@gmail.com>
18 // Copyright (C) 2008 Brad Hards <bradh@kde.org>
19 // Copyright (C) 2008, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
20 // Copyright (C) 2009-2013 Albert Astals Cid <aacid@kde.org>
21 // Copyright (C) 2009, 2010, 2012, 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
22 // Copyright (C) 2010 David Benjamin <davidben@mit.edu>
23 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
24 // Copyright (C) 2013 Fabio D'Urso <fabiodurso@hotmail.it>
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
29 //========================================================================
31 #ifndef GFX_H
32 #define GFX_H
34 #ifdef USE_GCC_PRAGMAS
35 #pragma interface
36 #endif
38 #include "poppler-config.h"
39 #include "goo/gtypes.h"
40 #include "goo/GooList.h"
41 #include "GfxState.h"
42 #include "Object.h"
43 #include "PopplerCache.h"
45 #include <vector>
47 class GooString;
48 class PDFDoc;
49 class XRef;
50 class Array;
51 class Stream;
52 class Parser;
53 class Dict;
54 class Function;
55 class OutputDev;
56 class GfxFontDict;
57 class GfxFont;
58 class GfxPattern;
59 class GfxTilingPattern;
60 class GfxShadingPattern;
61 class GfxShading;
62 class GfxFunctionShading;
63 class GfxAxialShading;
64 class GfxRadialShading;
65 class GfxGouraudTriangleShading;
66 class GfxPatchMeshShading;
67 struct GfxPatch;
68 class GfxState;
69 struct GfxColor;
70 class GfxColorSpace;
71 class Gfx;
72 class PDFRectangle;
73 class AnnotBorder;
74 class AnnotColor;
75 class Catalog;
76 struct MarkedContentStack;
78 //------------------------------------------------------------------------
80 enum GfxClipType {
81 clipNone,
82 clipNormal,
83 clipEO
86 enum TchkType {
87 tchkBool, // boolean
88 tchkInt, // integer
89 tchkNum, // number (integer or real)
90 tchkString, // string
91 tchkName, // name
92 tchkArray, // array
93 tchkProps, // properties (dictionary or name)
94 tchkSCN, // scn/SCN args (number of name)
95 tchkNone // used to avoid empty initializer lists
98 #define maxArgs 33
100 struct Operator {
101 char name[4];
102 int numArgs;
103 TchkType tchk[maxArgs];
104 void (Gfx::*func)(Object args[], int numArgs);
107 //------------------------------------------------------------------------
109 class GfxResources {
110 public:
112 GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA);
113 ~GfxResources();
115 GfxFont *lookupFont(char *name);
116 GBool lookupXObject(char *name, Object *obj);
117 GBool lookupXObjectNF(char *name, Object *obj);
118 GBool lookupMarkedContentNF(char *name, Object *obj);
119 void lookupColorSpace(const char *name, Object *obj);
120 GfxPattern *lookupPattern(char *name, OutputDev *out, GfxState *state);
121 GfxShading *lookupShading(char *name, OutputDev *out, GfxState *state);
122 GBool lookupGState(char *name, Object *obj);
123 GBool lookupGStateNF(char *name, Object *obj);
125 GfxResources *getNext() { return next; }
127 private:
129 GfxFontDict *fonts;
130 Object xObjDict;
131 Object colorSpaceDict;
132 Object patternDict;
133 Object shadingDict;
134 Object gStateDict;
135 PopplerObjectCache gStateCache;
136 Object propertiesDict;
137 GfxResources *next;
140 //------------------------------------------------------------------------
141 // Gfx
142 //------------------------------------------------------------------------
144 class Gfx {
145 public:
147 // Constructor for regular output.
148 Gfx(PDFDoc *docA, OutputDev *outA, int pageNum, Dict *resDict,
149 double hDPI, double vDPI, PDFRectangle *box,
150 PDFRectangle *cropBox, int rotate,
151 GBool (*abortCheckCbkA)(void *data) = NULL,
152 void *abortCheckCbkDataA = NULL, XRef *xrefA = NULL);
154 // Constructor for a sub-page object.
155 Gfx(PDFDoc *docA, OutputDev *outA, Dict *resDict,
156 PDFRectangle *box, PDFRectangle *cropBox,
157 GBool (*abortCheckCbkA)(void *data) = NULL,
158 void *abortCheckCbkDataA = NULL, XRef *xrefA = NULL);
159 #ifdef USE_CMS
160 void initDisplayProfile();
161 #endif
162 ~Gfx();
164 XRef *getXRef() { return xref; }
166 // Interpret a stream or array of streams.
167 void display(Object *obj, GBool topLevel = gTrue);
169 // Display an annotation, given its appearance (a Form XObject),
170 // border style, and bounding box (in default user space).
171 void drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor,
172 double xMin, double yMin, double xMax, double yMax, int rotate);
174 // Save graphics state.
175 void saveState();
177 // Push a new state guard
178 void pushStateGuard();
180 // Restore graphics state.
181 void restoreState();
183 // Pop to state guard and pop guard
184 void popStateGuard();
186 // Get the current graphics state object.
187 GfxState *getState() { return state; }
189 GBool checkTransparencyGroup(Dict *resDict);
191 void drawForm(Object *str, Dict *resDict, double *matrix, double *bbox,
192 GBool transpGroup = gFalse, GBool softMask = gFalse,
193 GfxColorSpace *blendingColorSpace = NULL,
194 GBool isolated = gFalse, GBool knockout = gFalse,
195 GBool alpha = gFalse, Function *transferFunc = NULL,
196 GfxColor *backdropColor = NULL);
198 void pushResources(Dict *resDict);
199 void popResources();
201 private:
203 PDFDoc *doc;
204 XRef *xref; // the xref table for this PDF file
205 Catalog *catalog; // the Catalog for this PDF file
206 OutputDev *out; // output device
207 GBool subPage; // is this a sub-page object?
208 GBool printCommands; // print the drawing commands (for debugging)
209 GBool profileCommands; // profile the drawing commands (for debugging)
210 GBool commandAborted; // did the previous command abort the drawing?
211 GfxResources *res; // resource stack
212 int updateLevel;
214 GfxState *state; // current graphics state
215 int stackHeight; // the height of the current graphics stack
216 std::vector<int> stateGuards; // a stack of state limits; to guard against unmatched pops
217 GBool fontChanged; // set if font or text matrix has changed
218 GfxClipType clip; // do a clip?
219 int ignoreUndef; // current BX/EX nesting level
220 double baseMatrix[6]; // default matrix for most recent
221 // page/form/pattern
222 int formDepth;
223 GBool ocState; // true if drawing is enabled, false if
224 // disabled
226 MarkedContentStack *mcStack; // current BMC/EMC stack
228 Parser *parser; // parser for page content stream(s)
230 std::set<int> formsDrawing; // the forms that are being drawn
232 GBool // callback to check for an abort
233 (*abortCheckCbk)(void *data);
234 void *abortCheckCbkData;
236 static Operator opTab[]; // table of operators
238 void go(GBool topLevel);
239 void execOp(Object *cmd, Object args[], int numArgs);
240 Operator *findOp(char *name);
241 GBool checkArg(Object *arg, TchkType type);
242 Goffset getPos();
244 int bottomGuard();
246 // graphics state operators
247 void opSave(Object args[], int numArgs);
248 void opRestore(Object args[], int numArgs);
249 void opConcat(Object args[], int numArgs);
250 void opSetDash(Object args[], int numArgs);
251 void opSetFlat(Object args[], int numArgs);
252 void opSetLineJoin(Object args[], int numArgs);
253 void opSetLineCap(Object args[], int numArgs);
254 void opSetMiterLimit(Object args[], int numArgs);
255 void opSetLineWidth(Object args[], int numArgs);
256 void opSetExtGState(Object args[], int numArgs);
257 void doSoftMask(Object *str, GBool alpha,
258 GfxColorSpace *blendingColorSpace,
259 GBool isolated, GBool knockout,
260 Function *transferFunc, GfxColor *backdropColor);
261 void opSetRenderingIntent(Object args[], int numArgs);
263 // color operators
264 void opSetFillGray(Object args[], int numArgs);
265 void opSetStrokeGray(Object args[], int numArgs);
266 void opSetFillCMYKColor(Object args[], int numArgs);
267 void opSetStrokeCMYKColor(Object args[], int numArgs);
268 void opSetFillRGBColor(Object args[], int numArgs);
269 void opSetStrokeRGBColor(Object args[], int numArgs);
270 void opSetFillColorSpace(Object args[], int numArgs);
271 void opSetStrokeColorSpace(Object args[], int numArgs);
272 void opSetFillColor(Object args[], int numArgs);
273 void opSetStrokeColor(Object args[], int numArgs);
274 void opSetFillColorN(Object args[], int numArgs);
275 void opSetStrokeColorN(Object args[], int numArgs);
277 // path segment operators
278 void opMoveTo(Object args[], int numArgs);
279 void opLineTo(Object args[], int numArgs);
280 void opCurveTo(Object args[], int numArgs);
281 void opCurveTo1(Object args[], int numArgs);
282 void opCurveTo2(Object args[], int numArgs);
283 void opRectangle(Object args[], int numArgs);
284 void opClosePath(Object args[], int numArgs);
286 // path painting operators
287 void opEndPath(Object args[], int numArgs);
288 void opStroke(Object args[], int numArgs);
289 void opCloseStroke(Object args[], int numArgs);
290 void opFill(Object args[], int numArgs);
291 void opEOFill(Object args[], int numArgs);
292 void opFillStroke(Object args[], int numArgs);
293 void opCloseFillStroke(Object args[], int numArgs);
294 void opEOFillStroke(Object args[], int numArgs);
295 void opCloseEOFillStroke(Object args[], int numArgs);
296 void doPatternFill(GBool eoFill);
297 void doPatternStroke();
298 void doPatternText();
299 void doPatternImageMask(Object *ref, Stream *str, int width, int height,
300 GBool invert, GBool inlineImg);
301 void doTilingPatternFill(GfxTilingPattern *tPat,
302 GBool stroke, GBool eoFill, GBool text);
303 void doShadingPatternFill(GfxShadingPattern *sPat,
304 GBool stroke, GBool eoFill, GBool text);
305 void opShFill(Object args[], int numArgs);
306 void doFunctionShFill(GfxFunctionShading *shading);
307 void doFunctionShFill1(GfxFunctionShading *shading,
308 double x0, double y0,
309 double x1, double y1,
310 GfxColor *colors, int depth);
311 void doAxialShFill(GfxAxialShading *shading);
312 void doRadialShFill(GfxRadialShading *shading);
313 void doGouraudTriangleShFill(GfxGouraudTriangleShading *shading);
314 void gouraudFillTriangle(double x0, double y0, GfxColor *color0,
315 double x1, double y1, GfxColor *color1,
316 double x2, double y2, GfxColor *color2,
317 int nComps, int depth, GfxState::ReusablePathIterator *path);
318 void gouraudFillTriangle(double x0, double y0, double color0,
319 double x1, double y1, double color1,
320 double x2, double y2, double color2,
321 double refineColorThreshold, int depth, GfxGouraudTriangleShading *shading, GfxState::ReusablePathIterator *path);
322 void doPatchMeshShFill(GfxPatchMeshShading *shading);
323 void fillPatch(GfxPatch *patch, int colorComps, int patchColorComps, double refineColorThreshold, int depth, GfxPatchMeshShading *shading);
324 void doEndPath();
326 // path clipping operators
327 void opClip(Object args[], int numArgs);
328 void opEOClip(Object args[], int numArgs);
330 // text object operators
331 void opBeginText(Object args[], int numArgs);
332 void opEndText(Object args[], int numArgs);
334 // text state operators
335 void opSetCharSpacing(Object args[], int numArgs);
336 void opSetFont(Object args[], int numArgs);
337 void opSetTextLeading(Object args[], int numArgs);
338 void opSetTextRender(Object args[], int numArgs);
339 void opSetTextRise(Object args[], int numArgs);
340 void opSetWordSpacing(Object args[], int numArgs);
341 void opSetHorizScaling(Object args[], int numArgs);
343 // text positioning operators
344 void opTextMove(Object args[], int numArgs);
345 void opTextMoveSet(Object args[], int numArgs);
346 void opSetTextMatrix(Object args[], int numArgs);
347 void opTextNextLine(Object args[], int numArgs);
349 // text string operators
350 void opShowText(Object args[], int numArgs);
351 void opMoveShowText(Object args[], int numArgs);
352 void opMoveSetShowText(Object args[], int numArgs);
353 void opShowSpaceText(Object args[], int numArgs);
354 void doShowText(GooString *s);
355 void doIncCharCount(GooString *s);
357 // XObject operators
358 void opXObject(Object args[], int numArgs);
359 void doImage(Object *ref, Stream *str, GBool inlineImg);
360 void doForm(Object *str);
362 // in-line image operators
363 void opBeginImage(Object args[], int numArgs);
364 Stream *buildImageStream();
365 void opImageData(Object args[], int numArgs);
366 void opEndImage(Object args[], int numArgs);
368 // type 3 font operators
369 void opSetCharWidth(Object args[], int numArgs);
370 void opSetCacheDevice(Object args[], int numArgs);
372 // compatibility operators
373 void opBeginIgnoreUndef(Object args[], int numArgs);
374 void opEndIgnoreUndef(Object args[], int numArgs);
376 // marked content operators
377 void opBeginMarkedContent(Object args[], int numArgs);
378 void opEndMarkedContent(Object args[], int numArgs);
379 void opMarkPoint(Object args[], int numArgs);
380 GfxState *saveStateStack();
381 void restoreStateStack(GfxState *oldState);
382 GBool contentIsHidden();
383 void pushMarkedContent();
384 void popMarkedContent();
387 #endif