/src/xpdf-4.05/xpdf/Gfx.h
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // Gfx.h |
4 | | // |
5 | | // Copyright 1996-2016 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef GFX_H |
10 | | #define GFX_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #include "gtypes.h" |
15 | | #include "gfile.h" |
16 | | #include "GfxState.h" |
17 | | |
18 | | class GString; |
19 | | class GList; |
20 | | class PDFDoc; |
21 | | class XRef; |
22 | | class Array; |
23 | | class Stream; |
24 | | class Parser; |
25 | | class Dict; |
26 | | class Function; |
27 | | class OutputDev; |
28 | | class GfxFontDict; |
29 | | class GfxFont; |
30 | | class Gfx; |
31 | | class PDFRectangle; |
32 | | class AnnotBorderStyle; |
33 | | |
34 | | //------------------------------------------------------------------------ |
35 | | |
36 | | enum GfxClipType { |
37 | | clipNone, |
38 | | clipNormal, |
39 | | clipEO |
40 | | }; |
41 | | |
42 | | enum TchkType { |
43 | | tchkBool, // boolean |
44 | | tchkInt, // integer |
45 | | tchkNum, // number (integer or real) |
46 | | tchkString, // string |
47 | | tchkName, // name |
48 | | tchkArray, // array |
49 | | tchkProps, // properties (dictionary or name) |
50 | | tchkSCN, // scn/SCN args (number of name) |
51 | | tchkNone // used to avoid empty initializer lists |
52 | | }; |
53 | | |
54 | 0 | #define maxArgs 33 |
55 | | |
56 | | struct Operator { |
57 | | char name[4]; |
58 | | int numArgs; |
59 | | TchkType tchk[maxArgs]; |
60 | | void (Gfx::*func)(Object args[], int numArgs); |
61 | | }; |
62 | | |
63 | | //------------------------------------------------------------------------ |
64 | | |
65 | | class GfxResources { |
66 | | public: |
67 | | |
68 | | GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA); |
69 | | ~GfxResources(); |
70 | | |
71 | | GfxFont *lookupFont(char *name); |
72 | | GfxFont *lookupFontByRef(Ref ref); |
73 | | GBool lookupXObject(const char *name, Object *obj); |
74 | | GBool lookupXObjectNF(const char *name, Object *obj); |
75 | | void lookupColorSpace(const char *name, Object *obj, GBool inherit = gTrue); |
76 | | GfxPattern *lookupPattern(const char *name |
77 | | ); |
78 | | GfxShading *lookupShading(const char *name |
79 | | ); |
80 | | GBool lookupGState(const char *name, Object *obj); |
81 | | GBool lookupPropertiesNF(const char *name, Object *obj); |
82 | | |
83 | 0 | GfxResources *getNext() { return next; } |
84 | | |
85 | | private: |
86 | | |
87 | | GBool valid; |
88 | | GfxFontDict *fonts; |
89 | | Object xObjDict; |
90 | | Object colorSpaceDict; |
91 | | Object patternDict; |
92 | | Object shadingDict; |
93 | | Object gStateDict; |
94 | | Object propsDict; |
95 | | GfxResources *next; |
96 | | }; |
97 | | |
98 | | //------------------------------------------------------------------------ |
99 | | // GfxMarkedContent |
100 | | //------------------------------------------------------------------------ |
101 | | |
102 | | enum GfxMarkedContentKind { |
103 | | gfxMCOptionalContent, |
104 | | gfxMCActualText, |
105 | | gfxMCStructureItem, |
106 | | gfxMCStructureItemAndActualText, |
107 | | gfxMCOther |
108 | | }; |
109 | | |
110 | | class GfxMarkedContent { |
111 | | public: |
112 | | |
113 | 0 | GfxMarkedContent(GfxMarkedContentKind kindA, GBool ocStateA) { |
114 | 0 | kind = kindA; |
115 | 0 | ocState = ocStateA; |
116 | 0 | } |
117 | 0 | ~GfxMarkedContent() {} |
118 | | |
119 | | GfxMarkedContentKind kind; |
120 | | GBool ocState; // true if drawing is enabled, false if |
121 | | // disabled |
122 | | }; |
123 | | |
124 | | //------------------------------------------------------------------------ |
125 | | // Gfx |
126 | | //------------------------------------------------------------------------ |
127 | | |
128 | | class Gfx { |
129 | | public: |
130 | | |
131 | | // Constructor for regular output. |
132 | | Gfx(PDFDoc *docA, OutputDev *outA, int pageNum, Dict *resDict, |
133 | | double hDPI, double vDPI, PDFRectangle *box, |
134 | | PDFRectangle *cropBox, int rotate, |
135 | | GBool (*abortCheckCbkA)(void *data) = NULL, |
136 | | void *abortCheckCbkDataA = NULL); |
137 | | |
138 | | // Constructor for a sub-page object. |
139 | | Gfx(PDFDoc *docA, OutputDev *outA, Dict *resDict, |
140 | | PDFRectangle *box, PDFRectangle *cropBox, |
141 | | GBool (*abortCheckCbkA)(void *data) = NULL, |
142 | | void *abortCheckCbkDataA = NULL); |
143 | | |
144 | | ~Gfx(); |
145 | | |
146 | | // Interpret a stream or array of streams. <objRef> should be a |
147 | | // reference wherever possible (for loop-checking). |
148 | | void display(Object *objRef, GBool topLevel = gTrue); |
149 | | |
150 | | // Display an annotation, given its appearance (a Form XObject), |
151 | | // border style, and bounding box (in default user space). |
152 | | void drawAnnot(Object *strRef, AnnotBorderStyle *borderStyle, |
153 | | double xMin, double yMin, double xMax, double yMax); |
154 | | |
155 | | // Save graphics state. |
156 | | void saveState(); |
157 | | |
158 | | // Restore graphics state. |
159 | | void restoreState(); |
160 | | |
161 | | // Get the current graphics state object. |
162 | 0 | GfxState *getState() { return state; } |
163 | | |
164 | | void drawForm(Object *strRef, Dict *resDict, double *matrix, double *bbox, |
165 | | GBool transpGroup = gFalse, GBool softMask = gFalse, |
166 | | GBool isolated = gFalse, GBool knockout = gFalse, |
167 | | GBool alpha = gFalse, Function *transferFunc = NULL, |
168 | | Object *backdropColorObj = NULL); |
169 | | |
170 | | // Take all of the content stream stack entries from <oldGfx>. This |
171 | | // is useful when creating a new Gfx object to handle a pattern, |
172 | | // etc., where it's useful to check for loops that span both Gfx |
173 | | // objects. This function should be called immediately after the |
174 | | // Gfx constructor, i.e., before processing any content streams with |
175 | | // the new Gfx object. |
176 | | void takeContentStreamStack(Gfx *oldGfx); |
177 | | |
178 | | // Clear the state stack and the marked content stack. |
179 | | void endOfPage(); |
180 | | |
181 | | private: |
182 | | |
183 | | PDFDoc *doc; |
184 | | XRef *xref; // the xref table for this PDF file |
185 | | OutputDev *out; // output device |
186 | | GBool subPage; // is this a sub-page object? |
187 | | GBool printCommands; // print the drawing commands (for debugging) |
188 | | GfxResources *res; // resource stack |
189 | | GfxFont *defaultFont; // font substituted for undefined fonts |
190 | | int opCounter; // operation counter (used to decide when |
191 | | // to check for an abort) |
192 | | |
193 | | GfxState *state; // current graphics state |
194 | | GBool fontChanged; // set if font or text matrix has changed |
195 | | GBool haveSavedClipPath; |
196 | | GfxClipType clip; // do a clip? |
197 | | int ignoreUndef; // current BX/EX nesting level |
198 | | double baseMatrix[6]; // default matrix for most recent |
199 | | // page/form/pattern |
200 | | int formDepth; |
201 | | GBool ocState; // true if drawing is enabled, false if |
202 | | // disabled |
203 | | GList *markedContentStack; // BMC/BDC/EMC stack [GfxMarkedContent] |
204 | | |
205 | | Parser *parser; // parser for page content stream(s) |
206 | | GList *contentStreamStack; // stack of open content streams, used |
207 | | // for loop-checking |
208 | | |
209 | | GBool // callback to check for an abort |
210 | | (*abortCheckCbk)(void *data); |
211 | | void *abortCheckCbkData; |
212 | | |
213 | | static Operator opTab[]; // table of operators |
214 | | |
215 | | GBool checkForContentStreamLoop(Object *ref); |
216 | | void go(GBool topLevel); |
217 | | void getContentObj(Object *obj); |
218 | | GBool execOp(Object *cmd, Object args[], int numArgs); |
219 | | Operator *findOp(char *name); |
220 | | GBool checkArg(Object *arg, TchkType type); |
221 | | GFileOffset getPos(); |
222 | | |
223 | | // graphics state operators |
224 | | void opSave(Object args[], int numArgs); |
225 | | void opRestore(Object args[], int numArgs); |
226 | | void opConcat(Object args[], int numArgs); |
227 | | void opSetDash(Object args[], int numArgs); |
228 | | void opSetFlat(Object args[], int numArgs); |
229 | | void opSetLineJoin(Object args[], int numArgs); |
230 | | void opSetLineCap(Object args[], int numArgs); |
231 | | void opSetMiterLimit(Object args[], int numArgs); |
232 | | void opSetLineWidth(Object args[], int numArgs); |
233 | | void opSetExtGState(Object args[], int numArgs); |
234 | | void doSoftMask(Object *str, Object *strRef, GBool alpha, |
235 | | GBool isolated, GBool knockout, |
236 | | Function *transferFunc, Object *backdropColorObj); |
237 | | void opSetRenderingIntent(Object args[], int numArgs); |
238 | | GfxRenderingIntent parseRenderingIntent(const char *name); |
239 | | |
240 | | // color operators |
241 | | void opSetFillGray(Object args[], int numArgs); |
242 | | void opSetStrokeGray(Object args[], int numArgs); |
243 | | void opSetFillCMYKColor(Object args[], int numArgs); |
244 | | void opSetStrokeCMYKColor(Object args[], int numArgs); |
245 | | void opSetFillRGBColor(Object args[], int numArgs); |
246 | | void opSetStrokeRGBColor(Object args[], int numArgs); |
247 | | void opSetFillColorSpace(Object args[], int numArgs); |
248 | | void opSetStrokeColorSpace(Object args[], int numArgs); |
249 | | void opSetFillColor(Object args[], int numArgs); |
250 | | void opSetStrokeColor(Object args[], int numArgs); |
251 | | void opSetFillColorN(Object args[], int numArgs); |
252 | | void opSetStrokeColorN(Object args[], int numArgs); |
253 | | |
254 | | // path segment operators |
255 | | void opMoveTo(Object args[], int numArgs); |
256 | | void opLineTo(Object args[], int numArgs); |
257 | | void opCurveTo(Object args[], int numArgs); |
258 | | void opCurveTo1(Object args[], int numArgs); |
259 | | void opCurveTo2(Object args[], int numArgs); |
260 | | void opRectangle(Object args[], int numArgs); |
261 | | void opClosePath(Object args[], int numArgs); |
262 | | |
263 | | // path painting operators |
264 | | void opEndPath(Object args[], int numArgs); |
265 | | void opStroke(Object args[], int numArgs); |
266 | | void opCloseStroke(Object args[], int numArgs); |
267 | | void opFill(Object args[], int numArgs); |
268 | | void opEOFill(Object args[], int numArgs); |
269 | | void opFillStroke(Object args[], int numArgs); |
270 | | void opCloseFillStroke(Object args[], int numArgs); |
271 | | void opEOFillStroke(Object args[], int numArgs); |
272 | | void opCloseEOFillStroke(Object args[], int numArgs); |
273 | | void doPatternFill(GBool eoFill); |
274 | | void doPatternStroke(); |
275 | | void doPatternText(GBool stroke); |
276 | | void doPatternImageMask(Object *ref, Stream *str, int width, int height, |
277 | | GBool invert, GBool inlineImg, GBool interpolate); |
278 | | void doTilingPatternFill(GfxTilingPattern *tPat, |
279 | | GBool stroke, GBool eoFill, GBool text); |
280 | | void doShadingPatternFill(GfxShadingPattern *sPat, |
281 | | GBool stroke, GBool eoFill, GBool text); |
282 | | void opShFill(Object args[], int numArgs); |
283 | | void doShFill(GfxShading *shading); |
284 | | void doFunctionShFill(GfxFunctionShading *shading); |
285 | | void doFunctionShFill1(GfxFunctionShading *shading, |
286 | | double x0, double y0, |
287 | | double x1, double y1, |
288 | | GfxColor *colors, int depth); |
289 | | void doAxialShFill(GfxAxialShading *shading); |
290 | | void doRadialShFill(GfxRadialShading *shading); |
291 | | void doGouraudTriangleShFill(GfxGouraudTriangleShading *shading); |
292 | | void gouraudFillTriangle(double x0, double y0, double *color0, |
293 | | double x1, double y1, double *color1, |
294 | | double x2, double y2, double *color2, |
295 | | GfxGouraudTriangleShading *shading, int depth); |
296 | | void doPatchMeshShFill(GfxPatchMeshShading *shading); |
297 | | void fillPatch(GfxPatch *patch, GfxPatchMeshShading *shading, int depth); |
298 | | void doEndPath(); |
299 | | |
300 | | // path clipping operators |
301 | | void opClip(Object args[], int numArgs); |
302 | | void opEOClip(Object args[], int numArgs); |
303 | | |
304 | | // text object operators |
305 | | void opBeginText(Object args[], int numArgs); |
306 | | void opEndText(Object args[], int numArgs); |
307 | | |
308 | | // text state operators |
309 | | void opSetCharSpacing(Object args[], int numArgs); |
310 | | void opSetFont(Object args[], int numArgs); |
311 | | void doSetFont(GfxFont *font, double size); |
312 | | void opSetTextLeading(Object args[], int numArgs); |
313 | | void opSetTextRender(Object args[], int numArgs); |
314 | | void opSetTextRise(Object args[], int numArgs); |
315 | | void opSetWordSpacing(Object args[], int numArgs); |
316 | | void opSetHorizScaling(Object args[], int numArgs); |
317 | | |
318 | | // text positioning operators |
319 | | void opTextMove(Object args[], int numArgs); |
320 | | void opTextMoveSet(Object args[], int numArgs); |
321 | | void opSetTextMatrix(Object args[], int numArgs); |
322 | | void opTextNextLine(Object args[], int numArgs); |
323 | | |
324 | | // text string operators |
325 | | void opShowText(Object args[], int numArgs); |
326 | | void opMoveShowText(Object args[], int numArgs); |
327 | | void opMoveSetShowText(Object args[], int numArgs); |
328 | | void opShowSpaceText(Object args[], int numArgs); |
329 | | void doShowText(GString *s); |
330 | | void doIncCharCount(GString *s); |
331 | | |
332 | | // XObject operators |
333 | | void opXObject(Object args[], int numArgs); |
334 | | GBool doImage(Object *ref, Stream *str, GBool inlineImg); |
335 | | void doForm(Object *strRef, Object *str); |
336 | | |
337 | | // in-line image operators |
338 | | void opBeginImage(Object args[], int numArgs); |
339 | | Stream *buildImageStream(GBool *haveLength); |
340 | | void opImageData(Object args[], int numArgs); |
341 | | void opEndImage(Object args[], int numArgs); |
342 | | |
343 | | // type 3 font operators |
344 | | void opSetCharWidth(Object args[], int numArgs); |
345 | | void opSetCacheDevice(Object args[], int numArgs); |
346 | | |
347 | | // compatibility operators |
348 | | void opBeginIgnoreUndef(Object args[], int numArgs); |
349 | | void opEndIgnoreUndef(Object args[], int numArgs); |
350 | | |
351 | | // marked content operators |
352 | | void opBeginMarkedContent(Object args[], int numArgs); |
353 | | void opEndMarkedContent(Object args[], int numArgs); |
354 | | void opMarkPoint(Object args[], int numArgs); |
355 | | |
356 | | GfxState *saveStateStack(); |
357 | | void restoreStateStack(GfxState *oldState); |
358 | | void pushResources(Dict *resDict); |
359 | | void popResources(); |
360 | | }; |
361 | | |
362 | | #endif |