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