filters

Gfx.h
1//========================================================================
2//
3// Gfx.h
4//
5// Copyright 1996-2002 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
20class GString;
21class XRef;
22class Array;
23class Stream;
24class Parser;
25class Dict;
26class OutputDev;
27class GfxFontDict;
28class GfxFont;
29class GfxPattern;
30class GfxShading;
31class GfxAxialShading;
32class GfxRadialShading;
33class GfxState;
34class Gfx;
35class PDFRectangle;
36
37//------------------------------------------------------------------------
38// Gfx
39//------------------------------------------------------------------------
40
41enum GfxClipType {
42 clipNone,
43 clipNormal,
44 clipEO
45};
46
47enum TchkType {
48 tchkBool, // boolean
49 tchkInt, // integer
50 tchkNum, // number (integer or real)
51 tchkString, // string
52 tchkName, // name
53 tchkArray, // array
54 tchkProps, // properties (dictionary or name)
55 tchkSCN, // scn/SCN args (number of name)
56 tchkNone // used to avoid empty initializer lists
57};
58
59#define maxArgs 8
60
61struct Operator {
62 char name[4];
63 int numArgs;
64 TchkType tchk[maxArgs];
65 void (Gfx::*func)(Object args[], int numArgs);
66};
67
68class GfxResources {
69public:
70
71 GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA);
72 ~GfxResources();
73
74 GfxFont *lookupFont(char *name);
75 GBool lookupXObject(char *name, Object *obj);
76 GBool lookupXObjectNF(char *name, Object *obj);
77 void lookupColorSpace(char *name, Object *obj);
78 GfxPattern *lookupPattern(char *name);
79 GfxShading *lookupShading(char *name);
80 GBool lookupGState(char *name, Object *obj);
81
82 GfxResources *getNext() { return next; }
83
84private:
85
86 GfxFontDict *fonts;
87 Object xObjDict;
88 Object colorSpaceDict;
89 Object patternDict;
90 Object shadingDict;
91 Object gStateDict;
92 GfxResources *next;
93};
94
95class Gfx {
96public:
97
98 // Constructor for regular output.
99 Gfx(XRef *xrefA, OutputDev *outA, int pageNum, Dict *resDict, double dpi,
100 PDFRectangle *box, GBool crop, PDFRectangle *cropBox, int rotate,
101 GBool (*abortCheckCbkA)(void *data) = NULL,
102 void *abortCheckCbkDataA = NULL);
103
104 // Constructor for a sub-page object.
105 Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
106 PDFRectangle *box, GBool crop, PDFRectangle *cropBox,
107 GBool (*abortCheckCbkA)(void *data) = NULL,
108 void *abortCheckCbkDataA = NULL);
109
110 ~Gfx();
111
112 // Interpret a stream or array of streams.
113 void display(Object *obj, GBool topLevel = gTrue);
114
115 // Display an annotation, given its appearance (a Form XObject) and
116 // bounding box (in default user space).
117 void doAnnot(Object *str, double xMin, double yMin,
118 double xMax, double yMax);
119
120 void pushResources(Dict *resDict);
121 void popResources();
122
123private:
124
125 XRef *xref; // the xref table for this PDF file
126 OutputDev *out; // output device
127 GBool subPage; // is this a sub-page object?
128 GBool printCommands; // print the drawing commands (for debugging)
129 GfxResources *res; // resource stack
130 int updateLevel;
131
132 GfxState *state; // current graphics state
133 GBool fontChanged; // set if font or text matrix has changed
134 GfxClipType clip; // do a clip?
135 int ignoreUndef; // current BX/EX nesting level
136 double baseMatrix[6]; // default matrix for most recent
137 // page/form/pattern
138
139 Parser *parser; // parser for page content stream(s)
140
141 GBool // callback to check for an abort
142 (*abortCheckCbk)(void *data);
143 void *abortCheckCbkData;
144
145 static Operator opTab[]; // table of operators
146
147 void go(GBool topLevel);
148 void execOp(Object *cmd, Object args[], int numArgs);
149 Operator *findOp(const char *name);
150 GBool checkArg(Object *arg, TchkType type);
151 int getPos();
152
153 // graphics state operators
154 void opSave(Object args[], int numArgs);
155 void opRestore(Object args[], int numArgs);
156 void opConcat(Object args[], int numArgs);
157 void opSetDash(Object args[], int numArgs);
158 void opSetFlat(Object args[], int numArgs);
159 void opSetLineJoin(Object args[], int numArgs);
160 void opSetLineCap(Object args[], int numArgs);
161 void opSetMiterLimit(Object args[], int numArgs);
162 void opSetLineWidth(Object args[], int numArgs);
163 void opSetExtGState(Object args[], int numArgs);
164 void opSetRenderingIntent(Object args[], int numArgs);
165
166 // color operators
167 void opSetFillGray(Object args[], int numArgs);
168 void opSetStrokeGray(Object args[], int numArgs);
169 void opSetFillCMYKColor(Object args[], int numArgs);
170 void opSetStrokeCMYKColor(Object args[], int numArgs);
171 void opSetFillRGBColor(Object args[], int numArgs);
172 void opSetStrokeRGBColor(Object args[], int numArgs);
173 void opSetFillColorSpace(Object args[], int numArgs);
174 void opSetStrokeColorSpace(Object args[], int numArgs);
175 void opSetFillColor(Object args[], int numArgs);
176 void opSetStrokeColor(Object args[], int numArgs);
177 void opSetFillColorN(Object args[], int numArgs);
178 void opSetStrokeColorN(Object args[], int numArgs);
179
180 // path segment operators
181 void opMoveTo(Object args[], int numArgs);
182 void opLineTo(Object args[], int numArgs);
183 void opCurveTo(Object args[], int numArgs);
184 void opCurveTo1(Object args[], int numArgs);
185 void opCurveTo2(Object args[], int numArgs);
186 void opRectangle(Object args[], int numArgs);
187 void opClosePath(Object args[], int numArgs);
188
189 // path painting operators
190 void opEndPath(Object args[], int numArgs);
191 void opStroke(Object args[], int numArgs);
192 void opCloseStroke(Object args[], int numArgs);
193 void opFill(Object args[], int numArgs);
194 void opEOFill(Object args[], int numArgs);
195 void opFillStroke(Object args[], int numArgs);
196 void opCloseFillStroke(Object args[], int numArgs);
197 void opEOFillStroke(Object args[], int numArgs);
198 void opCloseEOFillStroke(Object args[], int numArgs);
199 void doPatternFill(GBool eoFill);
200 void opShFill(Object args[], int numArgs);
201 void doAxialShFill(GfxAxialShading *shading);
202 void doRadialShFill(GfxRadialShading *shading);
203 void doEndPath();
204
205 // path clipping operators
206 void opClip(Object args[], int numArgs);
207 void opEOClip(Object args[], int numArgs);
208
209 // text object operators
210 void opBeginText(Object args[], int numArgs);
211 void opEndText(Object args[], int numArgs);
212
213 // text state operators
214 void opSetCharSpacing(Object args[], int numArgs);
215 void opSetFont(Object args[], int numArgs);
216 void opSetTextLeading(Object args[], int numArgs);
217 void opSetTextRender(Object args[], int numArgs);
218 void opSetTextRise(Object args[], int numArgs);
219 void opSetWordSpacing(Object args[], int numArgs);
220 void opSetHorizScaling(Object args[], int numArgs);
221
222 // text positioning operators
223 void opTextMove(Object args[], int numArgs);
224 void opTextMoveSet(Object args[], int numArgs);
225 void opSetTextMatrix(Object args[], int numArgs);
226 void opTextNextLine(Object args[], int numArgs);
227
228 // text string operators
229 void opShowText(Object args[], int numArgs);
230 void opMoveShowText(Object args[], int numArgs);
231 void opMoveSetShowText(Object args[], int numArgs);
232 void opShowSpaceText(Object args[], int numArgs);
233 void doShowText(GString *s);
234
235 // XObject operators
236 void opXObject(Object args[], int numArgs);
237 void doImage(Object *ref, Stream *str, GBool inlineImg);
238 void doForm(Object *str);
239 void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox);
240
241 // in-line image operators
242 void opBeginImage(Object args[], int numArgs);
243 Stream *buildImageStream();
244 void opImageData(Object args[], int numArgs);
245 void opEndImage(Object args[], int numArgs);
246
247 // type 3 font operators
248 void opSetCharWidth(Object args[], int numArgs);
249 void opSetCacheDevice(Object args[], int numArgs);
250
251 // compatibility operators
252 void opBeginIgnoreUndef(Object args[], int numArgs);
253 void opEndIgnoreUndef(Object args[], int numArgs);
254
255 // marked content operators
256 void opBeginMarkedContent(Object args[], int numArgs);
257 void opEndMarkedContent(Object args[], int numArgs);
258 void opMarkPoint(Object args[], int numArgs);
259};
260
261#endif