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