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