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