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