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