Gfx.h 13.3 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8
//========================================================================
//
// Gfx.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================

9 10 11 12
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
13 14 15
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
16 17 18
// Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
// Copyright (C) 2007 Iñigo Martínez <inigomartinez@gmail.com>
// Copyright (C) 2008 Brad Hards <bradh@kde.org>
19
// Copyright (C) 2008, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
20
// Copyright (C) 2009-2013, 2017, 2018 Albert Astals Cid <aacid@kde.org>
21
// Copyright (C) 2009, 2010, 2012, 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
22
// Copyright (C) 2010 David Benjamin <davidben@mit.edu>
23
// Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
24
// Copyright (C) 2013 Fabio D'Urso <fabiodurso@hotmail.it>
25
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
26 27 28 29 30 31
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
32 33 34 35 36 37 38
#ifndef GFX_H
#define GFX_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

39
#include "poppler-config.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
40
#include "goo/gtypes.h"
41
#include "goo/GooList.h"
42
#include "GfxState.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
43
#include "Object.h"
44
#include "PopplerCache.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
45

Albert Astals Cid's avatar
Albert Astals Cid committed
46 47
#include <vector>

Kristian Høgsberg's avatar
Kristian Høgsberg committed
48
class GooString;
49
class PDFDoc;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
50 51 52 53 54
class XRef;
class Array;
class Stream;
class Parser;
class Dict;
55
class Function;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
56 57 58 59 60 61 62 63 64 65
class OutputDev;
class GfxFontDict;
class GfxFont;
class GfxPattern;
class GfxTilingPattern;
class GfxShadingPattern;
class GfxShading;
class GfxFunctionShading;
class GfxAxialShading;
class GfxRadialShading;
66 67 68
class GfxGouraudTriangleShading;
class GfxPatchMeshShading;
struct GfxPatch;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
69 70
class GfxState;
struct GfxColor;
71
class GfxColorSpace;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
72 73
class Gfx;
class PDFRectangle;
74 75
class AnnotBorder;
class AnnotColor;
76
class Catalog;
77
struct MarkedContentStack;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

//------------------------------------------------------------------------

enum GfxClipType {
  clipNone,
  clipNormal,
  clipEO
};

enum TchkType {
  tchkBool,			// boolean
  tchkInt,			// integer
  tchkNum,			// number (integer or real)
  tchkString,			// string
  tchkName,			// name
  tchkArray,			// array
  tchkProps,			// properties (dictionary or name)
  tchkSCN,			// scn/SCN args (number of name)
  tchkNone			// used to avoid empty initializer lists
};

99
#define maxArgs 33
Kristian Høgsberg's avatar
Kristian Høgsberg committed
100 101 102 103 104 105 106 107

struct Operator {
  char name[4];
  int numArgs;
  TchkType tchk[maxArgs];
  void (Gfx::*func)(Object args[], int numArgs);
};

108 109
//------------------------------------------------------------------------

Kristian Høgsberg's avatar
Kristian Høgsberg committed
110 111 112 113 114 115
class GfxResources {
public:

  GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA);
  ~GfxResources();

116 117 118
  GfxResources(const GfxResources &) = delete;
  GfxResources& operator=(const GfxResources &other) = delete;

119 120
  GfxFont *lookupFont(const char *name);
  const GfxFont *lookupFont(const char *name) const;
121 122 123
  Object lookupXObject(const char *name);
  Object lookupXObjectNF(const char *name);
  Object lookupMarkedContentNF(const char *name);
Albert Astals Cid's avatar
Albert Astals Cid committed
124
  Object lookupColorSpace(const char *name);
125 126 127 128
  GfxPattern *lookupPattern(const char *name, OutputDev *out, GfxState *state);
  GfxShading *lookupShading(const char *name, OutputDev *out, GfxState *state);
  Object lookupGState(const char *name);
  Object lookupGStateNF(const char *name);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
129 130 131 132

  GfxResources *getNext() { return next; }

private:
133
  GfxFont *doLookupFont(const char *name) const;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
134 135 136 137 138 139 140

  GfxFontDict *fonts;
  Object xObjDict;
  Object colorSpaceDict;
  Object patternDict;
  Object shadingDict;
  Object gStateDict;
141
  PopplerObjectCache gStateCache;
142
  Object propertiesDict;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
143 144 145
  GfxResources *next;
};

146 147 148 149
//------------------------------------------------------------------------
// Gfx
//------------------------------------------------------------------------

Kristian Høgsberg's avatar
Kristian Høgsberg committed
150 151 152 153
class Gfx {
public:

  // Constructor for regular output.
154
  Gfx(PDFDoc *docA, OutputDev *outA, int pageNum, Dict *resDict,
155
      double hDPI, double vDPI, PDFRectangle *box,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
156 157
      PDFRectangle *cropBox, int rotate,
      GBool (*abortCheckCbkA)(void *data) = NULL,
158
      void *abortCheckCbkDataA = NULL, XRef *xrefA = NULL);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
159 160

  // Constructor for a sub-page object.
161
  Gfx(PDFDoc *docA, OutputDev *outA, Dict *resDict,
162
      PDFRectangle *box, PDFRectangle *cropBox,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
163
      GBool (*abortCheckCbkA)(void *data) = NULL,
164
      void *abortCheckCbkDataA = NULL, Gfx *gfxA = NULL);
165 166 167
#ifdef USE_CMS
  void initDisplayProfile();
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
168 169
  ~Gfx();

170 171 172
  Gfx(const Gfx &) = delete;
  Gfx& operator=(const Gfx &other) = delete;

173 174
  XRef *getXRef() { return xref; }

Kristian Høgsberg's avatar
Kristian Høgsberg committed
175 176 177
  // Interpret a stream or array of streams.
  void display(Object *obj, GBool topLevel = gTrue);

178 179
  // Display an annotation, given its appearance (a Form XObject),
  // border style, and bounding box (in default user space).
180
  void drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor,
181
		 double xMin, double yMin, double xMax, double yMax, int rotate);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
182 183 184 185

  // Save graphics state.
  void saveState();

186 187 188
  // Push a new state guard
  void pushStateGuard();

Kristian Høgsberg's avatar
Kristian Høgsberg committed
189 190 191
  // Restore graphics state.
  void restoreState();

192 193 194
  // Pop to state guard and pop guard
  void popStateGuard();

195 196 197
  // Get the current graphics state object.
  GfxState *getState() { return state; }

198 199
  GBool checkTransparencyGroup(Dict *resDict);

200
  void drawForm(Object *str, Dict *resDict, double *matrix, double *bbox,
201 202 203 204 205 206
	       GBool transpGroup = gFalse, GBool softMask = gFalse,
	       GfxColorSpace *blendingColorSpace = NULL,
	       GBool isolated = gFalse, GBool knockout = gFalse,
	       GBool alpha = gFalse, Function *transferFunc = NULL,
	       GfxColor *backdropColor = NULL);

207 208 209
  void pushResources(Dict *resDict);
  void popResources();

Kristian Høgsberg's avatar
Kristian Høgsberg committed
210 211
private:

212
  PDFDoc *doc;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
213
  XRef *xref;			// the xref table for this PDF file
214
  Catalog *catalog;		// the Catalog for this PDF file  
Kristian Høgsberg's avatar
Kristian Høgsberg committed
215 216 217
  OutputDev *out;		// output device
  GBool subPage;		// is this a sub-page object?
  GBool printCommands;		// print the drawing commands (for debugging)
218
  GBool profileCommands;	// profile the drawing commands (for debugging)
219
  GBool commandAborted;         // did the previous command abort the drawing?
Kristian Høgsberg's avatar
Kristian Høgsberg committed
220 221 222 223
  GfxResources *res;		// resource stack
  int updateLevel;

  GfxState *state;		// current graphics state
224
  int stackHeight;		// the height of the current graphics stack
Albert Astals Cid's avatar
Albert Astals Cid committed
225
  std::vector<int> stateGuards;   // a stack of state limits; to guard against unmatched pops
Kristian Høgsberg's avatar
Kristian Høgsberg committed
226 227 228 229 230 231
  GBool fontChanged;		// set if font or text matrix has changed
  GfxClipType clip;		// do a clip?
  int ignoreUndef;		// current BX/EX nesting level
  double baseMatrix[6];		// default matrix for most recent
				//   page/form/pattern
  int formDepth;
232 233
  GBool ocState;		// true if drawing is enabled, false if
				//   disabled
Kristian Høgsberg's avatar
Kristian Høgsberg committed
234

235
  MarkedContentStack *mcStack;	// current BMC/EMC stack
236

Kristian Høgsberg's avatar
Kristian Høgsberg committed
237
  Parser *parser;		// parser for page content stream(s)
238
  
239
  std::set<int> formsDrawing;	// the forms/patterns that are being drawn
240
  std::set<int> charProcDrawing;	// the charProc that are being drawn
241

Kristian Høgsberg's avatar
Kristian Høgsberg committed
242 243 244 245 246 247 248 249 250 251
  GBool				// callback to check for an abort
    (*abortCheckCbk)(void *data);
  void *abortCheckCbkData;

  static Operator opTab[];	// table of operators

  void go(GBool topLevel);
  void execOp(Object *cmd, Object args[], int numArgs);
  Operator *findOp(char *name);
  GBool checkArg(Object *arg, TchkType type);
252
  Goffset getPos();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
253

254 255
  int bottomGuard();

Kristian Høgsberg's avatar
Kristian Høgsberg committed
256 257 258 259 260 261 262 263 264 265 266
  // graphics state operators
  void opSave(Object args[], int numArgs);
  void opRestore(Object args[], int numArgs);
  void opConcat(Object args[], int numArgs);
  void opSetDash(Object args[], int numArgs);
  void opSetFlat(Object args[], int numArgs);
  void opSetLineJoin(Object args[], int numArgs);
  void opSetLineCap(Object args[], int numArgs);
  void opSetMiterLimit(Object args[], int numArgs);
  void opSetLineWidth(Object args[], int numArgs);
  void opSetExtGState(Object args[], int numArgs);
267 268 269 270
  void doSoftMask(Object *str, GBool alpha,
		  GfxColorSpace *blendingColorSpace,
		  GBool isolated, GBool knockout,
		  Function *transferFunc, GfxColor *backdropColor);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
  void opSetRenderingIntent(Object args[], int numArgs);

  // color operators
  void opSetFillGray(Object args[], int numArgs);
  void opSetStrokeGray(Object args[], int numArgs);
  void opSetFillCMYKColor(Object args[], int numArgs);
  void opSetStrokeCMYKColor(Object args[], int numArgs);
  void opSetFillRGBColor(Object args[], int numArgs);
  void opSetStrokeRGBColor(Object args[], int numArgs);
  void opSetFillColorSpace(Object args[], int numArgs);
  void opSetStrokeColorSpace(Object args[], int numArgs);
  void opSetFillColor(Object args[], int numArgs);
  void opSetStrokeColor(Object args[], int numArgs);
  void opSetFillColorN(Object args[], int numArgs);
  void opSetStrokeColorN(Object args[], int numArgs);

  // path segment operators
  void opMoveTo(Object args[], int numArgs);
  void opLineTo(Object args[], int numArgs);
  void opCurveTo(Object args[], int numArgs);
  void opCurveTo1(Object args[], int numArgs);
  void opCurveTo2(Object args[], int numArgs);
  void opRectangle(Object args[], int numArgs);
  void opClosePath(Object args[], int numArgs);

  // path painting operators
  void opEndPath(Object args[], int numArgs);
  void opStroke(Object args[], int numArgs);
  void opCloseStroke(Object args[], int numArgs);
  void opFill(Object args[], int numArgs);
  void opEOFill(Object args[], int numArgs);
  void opFillStroke(Object args[], int numArgs);
  void opCloseFillStroke(Object args[], int numArgs);
  void opEOFillStroke(Object args[], int numArgs);
  void opCloseEOFillStroke(Object args[], int numArgs);
  void doPatternFill(GBool eoFill);
307
  void doPatternStroke();
308 309 310
  void doPatternText();
  void doPatternImageMask(Object *ref, Stream *str, int width, int height,
			  GBool invert, GBool inlineImg);
311
  void doTilingPatternFill(GfxTilingPattern *tPat,
312
			   GBool stroke, GBool eoFill, GBool text);
313
  void doShadingPatternFill(GfxShadingPattern *sPat,
314
			    GBool stroke, GBool eoFill, GBool text);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
315 316 317 318 319 320 321 322
  void opShFill(Object args[], int numArgs);
  void doFunctionShFill(GfxFunctionShading *shading);
  void doFunctionShFill1(GfxFunctionShading *shading,
			 double x0, double y0,
			 double x1, double y1,
			 GfxColor *colors, int depth);
  void doAxialShFill(GfxAxialShading *shading);
  void doRadialShFill(GfxRadialShading *shading);
323 324 325 326
  void doGouraudTriangleShFill(GfxGouraudTriangleShading *shading);
  void gouraudFillTriangle(double x0, double y0, GfxColor *color0,
			   double x1, double y1, GfxColor *color1,
			   double x2, double y2, GfxColor *color2,
327 328 329 330 331
			   int nComps, int depth, GfxState::ReusablePathIterator *path);
  void gouraudFillTriangle(double x0, double y0, double color0,
			   double x1, double y1, double color1,
			   double x2, double y2, double color2,
			   double refineColorThreshold, int depth, GfxGouraudTriangleShading *shading, GfxState::ReusablePathIterator *path);
332
  void doPatchMeshShFill(GfxPatchMeshShading *shading);
333
  void fillPatch(GfxPatch *patch, int colorComps, int patchColorComps, double refineColorThreshold, int depth, GfxPatchMeshShading *shading);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
  void doEndPath();

  // path clipping operators
  void opClip(Object args[], int numArgs);
  void opEOClip(Object args[], int numArgs);

  // text object operators
  void opBeginText(Object args[], int numArgs);
  void opEndText(Object args[], int numArgs);

  // text state operators
  void opSetCharSpacing(Object args[], int numArgs);
  void opSetFont(Object args[], int numArgs);
  void opSetTextLeading(Object args[], int numArgs);
  void opSetTextRender(Object args[], int numArgs);
  void opSetTextRise(Object args[], int numArgs);
  void opSetWordSpacing(Object args[], int numArgs);
  void opSetHorizScaling(Object args[], int numArgs);

  // text positioning operators
  void opTextMove(Object args[], int numArgs);
  void opTextMoveSet(Object args[], int numArgs);
  void opSetTextMatrix(Object args[], int numArgs);
  void opTextNextLine(Object args[], int numArgs);

  // text string operators
  void opShowText(Object args[], int numArgs);
  void opMoveShowText(Object args[], int numArgs);
  void opMoveSetShowText(Object args[], int numArgs);
  void opShowSpaceText(Object args[], int numArgs);
364 365
  void doShowText(const GooString *s);
  void doIncCharCount(const GooString *s);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389

  // XObject operators
  void opXObject(Object args[], int numArgs);
  void doImage(Object *ref, Stream *str, GBool inlineImg);
  void doForm(Object *str);

  // in-line image operators
  void opBeginImage(Object args[], int numArgs);
  Stream *buildImageStream();
  void opImageData(Object args[], int numArgs);
  void opEndImage(Object args[], int numArgs);

  // type 3 font operators
  void opSetCharWidth(Object args[], int numArgs);
  void opSetCacheDevice(Object args[], int numArgs);

  // compatibility operators
  void opBeginIgnoreUndef(Object args[], int numArgs);
  void opEndIgnoreUndef(Object args[], int numArgs);

  // marked content operators
  void opBeginMarkedContent(Object args[], int numArgs);
  void opEndMarkedContent(Object args[], int numArgs);
  void opMarkPoint(Object args[], int numArgs);
390 391
  GfxState *saveStateStack();
  void restoreStateStack(GfxState *oldState);
392 393 394
  GBool contentIsHidden();
  void pushMarkedContent();
  void popMarkedContent();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
395 396 397
};

#endif