3
* PDF parsing module using libpoppler's facilities
7
* Copyright 1996-2003 Glyph & Cog, LLC
16
#ifdef USE_GCC_PRAGMAS
27
using Inkscape::Extension::Internal::SvgBuilder;
29
#include "goo/gtypes.h"
43
class GfxTilingPattern;
44
class GfxShadingPattern;
46
class GfxFunctionShading;
47
class GfxAxialShading;
48
class GfxRadialShading;
49
class GfxGouraudTriangleShading;
50
class GfxPatchMeshShading;
58
class AnnotBorderStyle;
62
//------------------------------------------------------------------------
74
tchkNum, // number (integer or real)
78
tchkProps, // properties (dictionary or name)
79
tchkSCN, // scn/SCN args (number of name)
80
tchkNone // used to avoid empty initializer lists
84
#define maxOperatorArgs 33
89
TchkType tchk[maxOperatorArgs];
90
void (PdfParser::*func)(Object args[], int numArgs);
93
#undef maxOperatorArgs
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
100
OpHistoryEntry *next; // next entry on stack
101
unsigned depth; // total number of entries descending from this
104
//------------------------------------------------------------------------
106
//------------------------------------------------------------------------
108
class ClipHistoryEntry {
111
ClipHistoryEntry(GfxPath *clipPath=NULL, GfxClipType clipType=clipNormal);
112
virtual ~ClipHistoryEntry();
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; }
124
ClipHistoryEntry *saved; // next clip path on stack
126
GfxPath *clipPath; // used as the path to be filled for an 'sh' operator
127
GfxClipType clipType;
129
ClipHistoryEntry(ClipHistoryEntry *other);
132
//------------------------------------------------------------------------
134
//------------------------------------------------------------------------
136
//------------------------------------------------------------------------
138
//------------------------------------------------------------------------
140
#define pdfFunctionShading 1
141
#define pdfAxialShading 2
142
#define pdfRadialShading 3
143
#define pdfGouraudTriangleShading 4
144
#define pdfPatchMeshShading 5
145
#define pdfNumShadingTypes 5
151
// Constructor for regular output.
152
PdfParser(XRef *xrefA, SvgBuilder *builderA, int pageNum, int rotate,
153
Dict *resDict, PDFRectangle *box, PDFRectangle *cropBox);
155
// Constructor for a sub-page object.
156
PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *builderA,
157
Dict *resDict, PDFRectangle *box);
159
virtual ~PdfParser();
161
// Interpret a stream or array of streams.
162
void parse(Object *obj, GBool topLevel = gTrue);
164
// Save graphics state.
167
// Restore graphics state.
170
// Get the current graphics state object.
171
GfxState *getState() { return state; }
173
// Set the precision of approximation for specific shading fills.
174
void setApproximationPrecision(int shadingType, double colorDelta, int maxDepth);
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
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
192
Parser *parser; // parser for page content stream(s)
194
static PdfOperator opTab[]; // table of operators
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
201
ClipHistoryEntry *clipHistory; // clip path stack
202
OpHistoryEntry *operatorHistory; // list containing the last N operators
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
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);
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);
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);
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);
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);
285
// path clipping operators
286
void opClip(Object args[], int numArgs);
287
void opEOClip(Object args[], int numArgs);
289
// text object operators
290
void opBeginText(Object args[], int numArgs);
291
void opEndText(Object args[], int numArgs);
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);
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);
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);
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);
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);
332
// type 3 font operators
333
void opSetCharWidth(Object args[], int numArgs);
334
void opSetCacheDevice(Object args[], int numArgs);
336
// compatibility operators
337
void opBeginIgnoreUndef(Object args[], int numArgs);
338
void opEndIgnoreUndef(Object args[], int numArgs);
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);
345
void pushResources(Dict *resDict);
349
#endif /* HAVE_POPPLER */
351
#endif /* PDF_PARSER_H */