~ubuntu-branches/debian/squeeze/inkscape/squeeze

« back to all changes in this revision

Viewing changes to src/extension/internal/pdfinput/pdf-parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 /** \file
 
3
 * PDF parsing module using libpoppler's facilities
 
4
 *
 
5
 * Derived from Gfx.h
 
6
 *
 
7
 * Copyright 1996-2003 Glyph & Cog, LLC
 
8
 *
 
9
 */
 
10
 
 
11
#ifndef PDF_PARSER_H
 
12
#define PDF_PARSER_H
 
13
 
 
14
#ifdef HAVE_POPPLER
 
15
 
 
16
#ifdef USE_GCC_PRAGMAS
 
17
#pragma interface
 
18
#endif
 
19
 
 
20
namespace Inkscape {
 
21
    namespace Extension {
 
22
        namespace Internal {
 
23
                class SvgBuilder;
 
24
        }
 
25
    }
 
26
}
 
27
using Inkscape::Extension::Internal::SvgBuilder;
 
28
 
 
29
#include "goo/gtypes.h"
 
30
#include "Object.h"
 
31
 
 
32
class GooString;
 
33
class XRef;
 
34
class Array;
 
35
class Stream;
 
36
class Parser;
 
37
class Dict;
 
38
class Function;
 
39
class OutputDev;
 
40
class GfxFontDict;
 
41
class GfxFont;
 
42
class GfxPattern;
 
43
class GfxTilingPattern;
 
44
class GfxShadingPattern;
 
45
class GfxShading;
 
46
class GfxFunctionShading;
 
47
class GfxAxialShading;
 
48
class GfxRadialShading;
 
49
class GfxGouraudTriangleShading;
 
50
class GfxPatchMeshShading;
 
51
struct GfxPatch;
 
52
class GfxState;
 
53
struct GfxColor;
 
54
class GfxColorSpace;
 
55
class Gfx;
 
56
class GfxResources;
 
57
class PDFRectangle;
 
58
class AnnotBorderStyle;
 
59
 
 
60
class PdfParser;
 
61
 
 
62
//------------------------------------------------------------------------
 
63
 
 
64
#ifndef GFX_H
 
65
enum GfxClipType {
 
66
    clipNone,
 
67
    clipNormal,
 
68
    clipEO
 
69
};
 
70
 
 
71
enum TchkType {
 
72
    tchkBool,                     // boolean
 
73
    tchkInt,                      // integer
 
74
    tchkNum,                      // number (integer or real)
 
75
    tchkString,                   // string
 
76
    tchkName,                     // name
 
77
    tchkArray,                    // array
 
78
    tchkProps,                    // properties (dictionary or name)
 
79
    tchkSCN,                      // scn/SCN args (number of name)
 
80
    tchkNone                      // used to avoid empty initializer lists
 
81
};
 
82
#endif /* GFX_H */
 
83
 
 
84
#define maxOperatorArgs 33
 
85
 
 
86
struct PdfOperator {
 
87
    char name[4];
 
88
    int numArgs;
 
89
    TchkType tchk[maxOperatorArgs];
 
90
    void (PdfParser::*func)(Object args[], int numArgs);
 
91
};
 
92
 
 
93
#undef maxOperatorArgs
 
94
 
 
95
struct OpHistoryEntry {
 
96
    const char *name;       // operator's name
 
97
    GfxState *state;        // saved state, NULL if none
 
98
    GBool executed;         // whether the operator has been executed
 
99
 
 
100
    OpHistoryEntry *next;   // next entry on stack
 
101
    unsigned depth;         // total number of entries descending from this
 
102
};
 
103
 
 
104
//------------------------------------------------------------------------
 
105
// ClipHistoryEntry
 
106
//------------------------------------------------------------------------
 
107
 
 
108
class ClipHistoryEntry {
 
109
public:
 
110
 
 
111
    ClipHistoryEntry(GfxPath *clipPath=NULL, GfxClipType clipType=clipNormal);
 
112
    virtual ~ClipHistoryEntry();
 
113
 
 
114
    // Manipulate clip path stack
 
115
    ClipHistoryEntry *save();
 
116
    ClipHistoryEntry *restore();
 
117
    GBool hasSaves() { return saved != NULL; }
 
118
    void setClip(GfxPath *newClipPath, GfxClipType newClipType=clipNormal);
 
119
    GfxPath *getClipPath() { return clipPath; }
 
120
    GfxClipType getClipType() { return clipType; }
 
121
 
 
122
private:
 
123
 
 
124
    ClipHistoryEntry *saved;    // next clip path on stack
 
125
        
 
126
    GfxPath *clipPath;        // used as the path to be filled for an 'sh' operator
 
127
    GfxClipType clipType;
 
128
 
 
129
    ClipHistoryEntry(ClipHistoryEntry *other);
 
130
};
 
131
 
 
132
//------------------------------------------------------------------------
 
133
// PdfParser
 
134
//------------------------------------------------------------------------
 
135
 
 
136
//------------------------------------------------------------------------
 
137
// constants
 
138
//------------------------------------------------------------------------
 
139
 
 
140
#define pdfFunctionShading  1
 
141
#define pdfAxialShading     2
 
142
#define pdfRadialShading    3
 
143
#define pdfGouraudTriangleShading  4
 
144
#define pdfPatchMeshShading 5
 
145
#define pdfNumShadingTypes 5
 
146
 
 
147
 
 
148
class PdfParser {
 
149
public:
 
150
 
 
151
  // Constructor for regular output.
 
152
  PdfParser(XRef *xrefA, SvgBuilder *builderA, int pageNum, int rotate,
 
153
            Dict *resDict, PDFRectangle *box, PDFRectangle *cropBox);
 
154
 
 
155
  // Constructor for a sub-page object.
 
156
  PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *builderA,
 
157
            Dict *resDict, PDFRectangle *box);
 
158
 
 
159
  virtual ~PdfParser();
 
160
 
 
161
  // Interpret a stream or array of streams.
 
162
  void parse(Object *obj, GBool topLevel = gTrue);
 
163
 
 
164
  // Save graphics state.
 
165
  void saveState();
 
166
 
 
167
  // Restore graphics state.
 
168
  void restoreState();
 
169
 
 
170
  // Get the current graphics state object.
 
171
  GfxState *getState() { return state; }
 
172
 
 
173
  // Set the precision of approximation for specific shading fills.
 
174
  void setApproximationPrecision(int shadingType, double colorDelta, int maxDepth);
 
175
 
 
176
private:
 
177
 
 
178
  XRef *xref;                   // the xref table for this PDF file
 
179
  SvgBuilder *builder;          // SVG generator
 
180
  GBool subPage;                // is this a sub-page object?
 
181
  GBool printCommands;          // print the drawing commands (for debugging)
 
182
  GfxResources *res;            // resource stack
 
183
 
 
184
  GfxState *state;              // current graphics state
 
185
  GBool fontChanged;            // set if font or text matrix has changed
 
186
  GfxClipType clip;             // do a clip?
 
187
  int ignoreUndef;              // current BX/EX nesting level
 
188
  double baseMatrix[6];         // default matrix for most recent
 
189
                                //   page/form/pattern
 
190
  int formDepth;
 
191
 
 
192
  Parser *parser;               // parser for page content stream(s)
 
193
 
 
194
  static PdfOperator opTab[];   // table of operators
 
195
 
 
196
  int colorDeltas[pdfNumShadingTypes];
 
197
                                // max deltas allowed in any color component
 
198
                                // for the approximation of shading fills
 
199
  int maxDepths[pdfNumShadingTypes];             // max recursive depths
 
200
 
 
201
  ClipHistoryEntry *clipHistory;    // clip path stack
 
202
  OpHistoryEntry *operatorHistory;  // list containing the last N operators
 
203
 
 
204
  void setDefaultApproximationPrecision();  // init color deltas
 
205
  void pushOperator(const char *name);
 
206
  OpHistoryEntry *popOperator();
 
207
  const char *getPreviousOperator(unsigned int look_back=1);    // returns the nth previous operator's name
 
208
 
 
209
  void go(GBool topLevel);
 
210
  void execOp(Object *cmd, Object args[], int numArgs);
 
211
  PdfOperator *findOp(char *name);
 
212
  GBool checkArg(Object *arg, TchkType type);
 
213
  int getPos();
 
214
 
 
215
  // graphics state operators
 
216
  void opSave(Object args[], int numArgs);
 
217
  void opRestore(Object args[], int numArgs);
 
218
  void opConcat(Object args[], int numArgs);
 
219
  void opSetDash(Object args[], int numArgs);
 
220
  void opSetFlat(Object args[], int numArgs);
 
221
  void opSetLineJoin(Object args[], int numArgs);
 
222
  void opSetLineCap(Object args[], int numArgs);
 
223
  void opSetMiterLimit(Object args[], int numArgs);
 
224
  void opSetLineWidth(Object args[], int numArgs);
 
225
  void opSetExtGState(Object args[], int numArgs);
 
226
  void doSoftMask(Object *str, GBool alpha,
 
227
                  GfxColorSpace *blendingColorSpace,
 
228
                  GBool isolated, GBool knockout,
 
229
                  Function *transferFunc, GfxColor *backdropColor);
 
230
  void opSetRenderingIntent(Object args[], int numArgs);
 
231
 
 
232
  // color operators
 
233
  void opSetFillGray(Object args[], int numArgs);
 
234
  void opSetStrokeGray(Object args[], int numArgs);
 
235
  void opSetFillCMYKColor(Object args[], int numArgs);
 
236
  void opSetStrokeCMYKColor(Object args[], int numArgs);
 
237
  void opSetFillRGBColor(Object args[], int numArgs);
 
238
  void opSetStrokeRGBColor(Object args[], int numArgs);
 
239
  void opSetFillColorSpace(Object args[], int numArgs);
 
240
  void opSetStrokeColorSpace(Object args[], int numArgs);
 
241
  void opSetFillColor(Object args[], int numArgs);
 
242
  void opSetStrokeColor(Object args[], int numArgs);
 
243
  void opSetFillColorN(Object args[], int numArgs);
 
244
  void opSetStrokeColorN(Object args[], int numArgs);
 
245
 
 
246
  // path segment operators
 
247
  void opMoveTo(Object args[], int numArgs);
 
248
  void opLineTo(Object args[], int numArgs);
 
249
  void opCurveTo(Object args[], int numArgs);
 
250
  void opCurveTo1(Object args[], int numArgs);
 
251
  void opCurveTo2(Object args[], int numArgs);
 
252
  void opRectangle(Object args[], int numArgs);
 
253
  void opClosePath(Object args[], int numArgs);
 
254
 
 
255
  // path painting operators
 
256
  void opEndPath(Object args[], int numArgs);
 
257
  void opStroke(Object args[], int numArgs);
 
258
  void opCloseStroke(Object args[], int numArgs);
 
259
  void opFill(Object args[], int numArgs);
 
260
  void opEOFill(Object args[], int numArgs);
 
261
  void opFillStroke(Object args[], int numArgs);
 
262
  void opCloseFillStroke(Object args[], int numArgs);
 
263
  void opEOFillStroke(Object args[], int numArgs);
 
264
  void opCloseEOFillStroke(Object args[], int numArgs);
 
265
  void doFillAndStroke(GBool eoFill);
 
266
  void doPatternFillFallback(GBool eoFill);
 
267
  void doPatternStrokeFallback();
 
268
  void doShadingPatternFillFallback(GfxShadingPattern *sPat,
 
269
                                    GBool stroke, GBool eoFill);
 
270
  void opShFill(Object args[], int numArgs);
 
271
  void doFunctionShFill(GfxFunctionShading *shading);
 
272
  void doFunctionShFill1(GfxFunctionShading *shading,
 
273
                         double x0, double y0,
 
274
                         double x1, double y1,
 
275
                         GfxColor *colors, int depth);
 
276
  void doGouraudTriangleShFill(GfxGouraudTriangleShading *shading);
 
277
  void gouraudFillTriangle(double x0, double y0, GfxColor *color0,
 
278
                           double x1, double y1, GfxColor *color1,
 
279
                           double x2, double y2, GfxColor *color2,
 
280
                           int nComps, int depth);
 
281
  void doPatchMeshShFill(GfxPatchMeshShading *shading);
 
282
  void fillPatch(GfxPatch *patch, int nComps, int depth);
 
283
  void doEndPath();
 
284
 
 
285
  // path clipping operators
 
286
  void opClip(Object args[], int numArgs);
 
287
  void opEOClip(Object args[], int numArgs);
 
288
 
 
289
  // text object operators
 
290
  void opBeginText(Object args[], int numArgs);
 
291
  void opEndText(Object args[], int numArgs);
 
292
 
 
293
  // text state operators
 
294
  void opSetCharSpacing(Object args[], int numArgs);
 
295
  void opSetFont(Object args[], int numArgs);
 
296
  void opSetTextLeading(Object args[], int numArgs);
 
297
  void opSetTextRender(Object args[], int numArgs);
 
298
  void opSetTextRise(Object args[], int numArgs);
 
299
  void opSetWordSpacing(Object args[], int numArgs);
 
300
  void opSetHorizScaling(Object args[], int numArgs);
 
301
 
 
302
  // text positioning operators
 
303
  void opTextMove(Object args[], int numArgs);
 
304
  void opTextMoveSet(Object args[], int numArgs);
 
305
  void opSetTextMatrix(Object args[], int numArgs);
 
306
  void opTextNextLine(Object args[], int numArgs);
 
307
 
 
308
  // text string operators
 
309
  void opShowText(Object args[], int numArgs);
 
310
  void opMoveShowText(Object args[], int numArgs);
 
311
  void opMoveSetShowText(Object args[], int numArgs);
 
312
  void opShowSpaceText(Object args[], int numArgs);
 
313
  void doShowText(GooString *s);
 
314
 
 
315
  // XObject operators
 
316
  void opXObject(Object args[], int numArgs);
 
317
  void doImage(Object *ref, Stream *str, GBool inlineImg);
 
318
  void doForm(Object *str);
 
319
  void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox,
 
320
               GBool transpGroup = gFalse, GBool softMask = gFalse,
 
321
               GfxColorSpace *blendingColorSpace = NULL,
 
322
               GBool isolated = gFalse, GBool knockout = gFalse,
 
323
               GBool alpha = gFalse, Function *transferFunc = NULL,
 
324
               GfxColor *backdropColor = NULL);
 
325
 
 
326
  // in-line image operators
 
327
  void opBeginImage(Object args[], int numArgs);
 
328
  Stream *buildImageStream();
 
329
  void opImageData(Object args[], int numArgs);
 
330
  void opEndImage(Object args[], int numArgs);
 
331
 
 
332
  // type 3 font operators
 
333
  void opSetCharWidth(Object args[], int numArgs);
 
334
  void opSetCacheDevice(Object args[], int numArgs);
 
335
 
 
336
  // compatibility operators
 
337
  void opBeginIgnoreUndef(Object args[], int numArgs);
 
338
  void opEndIgnoreUndef(Object args[], int numArgs);
 
339
 
 
340
  // marked content operators
 
341
  void opBeginMarkedContent(Object args[], int numArgs);
 
342
  void opEndMarkedContent(Object args[], int numArgs);
 
343
  void opMarkPoint(Object args[], int numArgs);
 
344
 
 
345
  void pushResources(Dict *resDict);
 
346
  void popResources();
 
347
};
 
348
 
 
349
#endif /* HAVE_POPPLER */
 
350
 
 
351
#endif /* PDF_PARSER_H */