OutputDev.h 15 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8
//========================================================================
//
// OutputDev.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) 2006 Thorkild Stray <thorkild@ifi.uio.no>
// Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>
19
// Copyright (C) 2007, 2011, 2017 Adrian Johnson <ajohnson@redneon.com>
20
// Copyright (C) 2009-2013, 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
Albert Astals Cid's avatar
Albert Astals Cid committed
21
// Copyright (C) 2009, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
22
// Copyright (C) 2009, 2012, 2013 Albert Astals Cid <aacid@kde.org>
23
// Copyright (C) 2010 Christian Feuersnger <cfeuersaenger@googlemail.com>
24
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
25
// Copyright (C) 2012 William Bader <williambader@hotmail.com>
26
// Copyright (C) 2017, 2018 Oliver Sander <oliver.sander@tu-dresden.de>
27
// Copyright (C) 2018 Klarlvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
28
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
29 30 31 32 33 34
//
// 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
35 36 37 38 39 40 41
#ifndef OUTPUTDEV_H
#define OUTPUTDEV_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

42
#include "poppler-config.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
43 44
#include "goo/gtypes.h"
#include "CharTypes.h"
45
#include "Object.h"
46
#include "PopplerCache.h"
47 48 49 50
#include "ProfileData.h"
#include <memory>
#include <unordered_map>
#include <string>
Kristian Høgsberg's avatar
Kristian Høgsberg committed
51

52
class Annot;
53
class Dict;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
54 55
class GooString;
class GfxState;
56
class Gfx;
57
struct GfxColor;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
58 59
class GfxColorSpace;
class GfxImageColorMap;
60 61
class GfxFunctionShading;
class GfxAxialShading;
62 63
class GfxGouraudTriangleShading;
class GfxPatchMeshShading;
64
class GfxRadialShading;
65 66
class GfxGouraudTriangleShading;
class GfxPatchMeshShading;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
67
class Stream;
68
class Links;
69
class AnnotLink;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
70
class Catalog;
71 72
class Page;
class Function;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
73 74 75 76 77 78 79 80 81

//------------------------------------------------------------------------
// OutputDev
//------------------------------------------------------------------------

class OutputDev {
public:

  // Constructor.
82 83 84 85 86 87
  OutputDev() 
#ifdef USE_CMS
 : iccColorSpaceCache(5)
#endif
  {
  }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
88 89 90 91 92 93 94 95 96 97 98 99 100

  // Destructor.
  virtual ~OutputDev() {}

  //----- get info about output device

  // Does this device use upside-down coordinates?
  // (Upside-down means (0,0) is the top left corner of the page.)
  virtual GBool upsideDown() = 0;

  // Does this device use drawChar() or drawString()?
  virtual GBool useDrawChar() = 0;

101 102 103 104 105
  // Does this device use tilingPatternFill()?  If this returns false,
  // tiling pattern fills will be reduced to a series of other drawing
  // operations.
  virtual GBool useTilingPatternFill() { return gFalse; }

106 107 108
  // Does this device support specific shading types?
  // see gouraudTriangleShadedFill() and patchMeshShadedFill()
  virtual GBool useShadedFills(int type) { return gFalse; }
109

110 111 112
  // Does this device use FillColorStop()?
  virtual GBool useFillColorStop() { return gFalse; }

113 114 115 116
  // Does this device use drawForm()?  If this returns false,
  // form-type XObjects will be interpreted (i.e., unrolled).
  virtual GBool useDrawForm() { return gFalse; }

Kristian Høgsberg's avatar
Kristian Høgsberg committed
117 118 119 120 121 122 123
  // Does this device use beginType3Char/endType3Char?  Otherwise,
  // text in Type 3 fonts will be drawn with drawChar/drawString.
  virtual GBool interpretType3Chars() = 0;

  // Does this device need non-text content?
  virtual GBool needNonText() { return gTrue; }

124 125 126
  // Does this device require incCharCount to be called for text on
  // non-shown layers?
  virtual GBool needCharCount() { return gFalse; }
127 128 129 130
  
  // Does this device need to clip pages to the crop box even when the
  // box is the crop box?
  virtual GBool needClipToCropBox() { return gFalse; }
131

Kristian Høgsberg's avatar
Kristian Høgsberg committed
132 133 134 135 136
  //----- initialization and control

  // Set default transform matrix.
  virtual void setDefaultCTM(double *ctm);

137 138 139 140 141 142 143
  // Check to see if a page slice should be displayed.  If this
  // returns false, the page display is aborted.  Typically, an
  // OutputDev will use some alternate means to display the page
  // before returning false.
  virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
			       int rotate, GBool useMediaBox, GBool crop,
			       int sliceX, int sliceY, int sliceW, int sliceH,
144
			       GBool printing,
145
			       GBool (* abortCheckCbk)(void *data) = NULL,
146 147 148
			       void * abortCheckCbkData = NULL,
			       GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
			       void *annotDisplayDecideCbkData = NULL)
149 150
    { return gTrue; }

Kristian Høgsberg's avatar
Kristian Høgsberg committed
151
  // Start a page.
Thomas Freitag's avatar
Thomas Freitag committed
152
  virtual void startPage(int pageNum, GfxState *state, XRef *xref) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
153 154 155 156 157 158 159 160 161 162 163 164 165

  // End a page.
  virtual void endPage() {}

  // Dump page contents to display.
  virtual void dump() {}

  //----- coordinate conversion

  // Convert between device and user coordinates.
  virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy);
  virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy);

166 167 168
  double *getDefCTM() { return defCTM; }
  double *getDefICTM() { return defICTM; }

Kristian Høgsberg's avatar
Kristian Høgsberg committed
169
  //----- save/restore graphics state
170 171
  virtual void saveState(GfxState * /*state*/) {}
  virtual void restoreState(GfxState * /*state*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
172 173 174

  //----- update graphics state
  virtual void updateAll(GfxState *state);
175 176 177 178 179 180

  // Update the Current Transformation Matrix (CTM), i.e., the new matrix
  // given in m11, ..., m32 is combined with the current value of the CTM.
  // At the same time, when this method is called, state->getCTM() already
  // contains the correct new CTM, so one may as well replace the
  // CTM of the renderer with that.
181 182 183 184 185 186 187 188
  virtual void updateCTM(GfxState * /*state*/, double /*m11*/, double /*m12*/,
			 double /*m21*/, double /*m22*/, double /*m31*/, double /*m32*/) {}
  virtual void updateLineDash(GfxState * /*state*/) {}
  virtual void updateFlatness(GfxState * /*state*/) {}
  virtual void updateLineJoin(GfxState * /*state*/) {}
  virtual void updateLineCap(GfxState * /*state*/) {}
  virtual void updateMiterLimit(GfxState * /*state*/) {}
  virtual void updateLineWidth(GfxState * /*state*/) {}
189
  virtual void updateStrokeAdjust(GfxState * /*state*/) {}
190 191
  virtual void updateAlphaIsShape(GfxState * /*state*/) {}
  virtual void updateTextKnockout(GfxState * /*state*/) {}
192 193 194 195 196 197 198
  virtual void updateFillColorSpace(GfxState * /*state*/) {}
  virtual void updateStrokeColorSpace(GfxState * /*state*/) {}
  virtual void updateFillColor(GfxState * /*state*/) {}
  virtual void updateStrokeColor(GfxState * /*state*/) {}
  virtual void updateBlendMode(GfxState * /*state*/) {}
  virtual void updateFillOpacity(GfxState * /*state*/) {}
  virtual void updateStrokeOpacity(GfxState * /*state*/) {}
199 200
  virtual void updatePatternOpacity(GfxState * /*state*/) {}
  virtual void clearPatternOpacity(GfxState * /*state*/) {}
201 202
  virtual void updateFillOverprint(GfxState * /*state*/) {}
  virtual void updateStrokeOverprint(GfxState * /*state*/) {}
203
  virtual void updateOverprintMode(GfxState * /*state*/) {}
204
  virtual void updateTransfer(GfxState * /*state*/) {}
205
  virtual void updateFillColorStop(GfxState * /*state*/, double /*offset*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
206 207

  //----- update text state
208 209 210 211 212 213 214 215 216
  virtual void updateFont(GfxState * /*state*/) {}
  virtual void updateTextMat(GfxState * /*state*/) {}
  virtual void updateCharSpace(GfxState * /*state*/) {}
  virtual void updateRender(GfxState * /*state*/) {}
  virtual void updateRise(GfxState * /*state*/) {}
  virtual void updateWordSpace(GfxState * /*state*/) {}
  virtual void updateHorizScaling(GfxState * /*state*/) {}
  virtual void updateTextPos(GfxState * /*state*/) {}
  virtual void updateTextShift(GfxState * /*state*/, double /*shift*/) {}
217 218
  virtual void saveTextPos(GfxState * /*state*/) {}
  virtual void restoreTextPos(GfxState * /*state*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
219 220

  //----- path painting
221 222 223
  virtual void stroke(GfxState * /*state*/) {}
  virtual void fill(GfxState * /*state*/) {}
  virtual void eoFill(GfxState * /*state*/) {}
224
  virtual GBool tilingPatternFill(GfxState * /*state*/, Gfx * /*gfx*/, Catalog * /*cat*/, Object * /*str*/,
225
				  double * /*pmat*/, int /*paintType*/, int /*tilingType*/, Dict * /*resDict*/,
226 227 228 229
				  double * /*mat*/, double * /*bbox*/,
				  int /*x0*/, int /*y0*/, int /*x1*/, int /*y1*/,
				  double /*xStep*/, double /*yStep*/)
    { return gFalse; }
230 231 232
  virtual GBool functionShadedFill(GfxState * /*state*/,
				   GfxFunctionShading * /*shading*/)
    { return gFalse; }
233
  virtual GBool axialShadedFill(GfxState * /*state*/, GfxAxialShading * /*shading*/, double /*tMin*/, double /*tMax*/)
234
    { return gFalse; }
235 236
  virtual GBool axialShadedSupportExtend(GfxState * /*state*/, GfxAxialShading * /*shading*/)
    { return gFalse; }
237
  virtual GBool radialShadedFill(GfxState * /*state*/, GfxRadialShading * /*shading*/, double /*sMin*/, double /*sMax*/)
238
    { return gFalse; }
239 240
  virtual GBool radialShadedSupportExtend(GfxState * /*state*/, GfxRadialShading * /*shading*/)
    { return gFalse; }
241 242 243 244
  virtual GBool gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading)
    { return gFalse; }
  virtual GBool patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading)
    { return gFalse; }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
245 246

  //----- path clipping
247 248
  virtual void clip(GfxState * /*state*/) {}
  virtual void eoClip(GfxState * /*state*/) {}
249
  virtual void clipToStrokePath(GfxState * /*state*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
250 251

  //----- text drawing
252 253
  virtual void beginStringOp(GfxState * /*state*/) {}
  virtual void endStringOp(GfxState * /*state*/) {}
254
  virtual void beginString(GfxState * /*state*/, const GooString * /*s*/) {}
255
  virtual void endString(GfxState * /*state*/) {}
256 257 258 259 260 261 262 263 264 265

  // Draw one glyph at a specified position
  //
  // Arguments are:
  // CharCode code: This is the character code in the content stream. It needs to be mapped back to a glyph index.
  // int nBytes: The text strings in the content stream can consists of either 8-bit or 16-bit
  //             character codes depending on the font. nBytes is the number of bytes in the character code.
  // Unicode *u: The UCS-4 mapping used for text extraction (TextOutputDev).
  // int uLen: The number of unicode entries in u.  Usually '1', for a single character,
  //           but it may also have larger values, for example for ligatures.
266 267 268 269
  virtual void drawChar(GfxState * /*state*/, double /*x*/, double /*y*/,
			double /*dx*/, double /*dy*/,
			double /*originX*/, double /*originY*/,
			CharCode /*code*/, int /*nBytes*/, Unicode * /*u*/, int /*uLen*/) {}
270
  virtual void drawString(GfxState * /*state*/, const GooString * /*s*/) {}
271 272 273 274
  virtual GBool beginType3Char(GfxState * /*state*/, double /*x*/, double /*y*/,
			       double /*dx*/, double /*dy*/,
			       CharCode /*code*/, Unicode * /*u*/, int /*uLen*/);
  virtual void endType3Char(GfxState * /*state*/) {}
275
  virtual void beginTextObject(GfxState * /*state*/) {}
276
  virtual void endTextObject(GfxState * /*state*/) {}
277
  virtual void incCharCount(int /*nChars*/) {}
278
  virtual void beginActualText(GfxState * /*state*/, const GooString * /*text*/ ) {}
279
  virtual void endActualText(GfxState * /*state*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
280 281

  //----- image drawing
282 283 284 285 286
  // Draw an image mask.  An image mask is a one-bit-per-pixel image, where each pixel
  // can only be 'fill color' or 'transparent'.
  //
  // If 'invert' is false, a sample value of 0 marks the page with the current color,
  // and a 1 leaves the previous contents unchanged. If 'invert' is true, these meanings are reversed.
Kristian Høgsberg's avatar
Kristian Høgsberg committed
287
  virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
288
			     int width, int height, GBool invert, GBool interpolate,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
289
			     GBool inlineImg);
290 291 292
  virtual void setSoftMaskFromImageMask(GfxState *state,
					Object *ref, Stream *str,
					int width, int height, GBool invert,
293 294
					GBool inlineImg, double *baseMatrix);
  virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
295 296
  virtual void drawImage(GfxState *state, Object *ref, Stream *str,
			 int width, int height, GfxImageColorMap *colorMap,
297
			 GBool interpolate, int *maskColors, GBool inlineImg);
298 299
  virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
			       int width, int height,
300
			       GfxImageColorMap *colorMap, GBool interpolate,
301
			       Stream *maskStr, int maskWidth, int maskHeight,
302
			       GBool maskInvert, GBool maskInterpolate);
303 304 305
  virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
				   int width, int height,
				   GfxImageColorMap *colorMap,
306
				   GBool interpolate,
307 308
				   Stream *maskStr,
				   int maskWidth, int maskHeight,
309 310
				   GfxImageColorMap *maskColorMap,
				   GBool maskInterpolate);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
311

312 313
  //----- grouping operators

314
  virtual void endMarkedContent(GfxState *state);
315 316 317
  virtual void beginMarkedContent(const char *name, Dict *properties);
  virtual void markPoint(const char *name);
  virtual void markPoint(const char *name, Dict *properties);
318 319


320

321
#ifdef OPI_SUPPORT
Kristian Høgsberg's avatar
Kristian Høgsberg committed
322 323 324 325 326 327
  //----- OPI functions
  virtual void opiBegin(GfxState *state, Dict *opiDict);
  virtual void opiEnd(GfxState *state, Dict *opiDict);
#endif

  //----- Type 3 font operators
328 329 330
  virtual void type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/) {}
  virtual void type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/,
		       double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
331

332 333 334
  //----- form XObjects
  virtual void drawForm(Ref /*id*/) {}

Kristian Høgsberg's avatar
Kristian Høgsberg committed
335
  //----- PostScript XObjects
336
  virtual void psXObject(Stream * /*psStream*/, Stream * /*level1Stream*/) {}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
337

338
  //----- Profiling
339 340 341
  void startProfile();
  std::unordered_map<std::string, ProfileData>* getProfileHash() const { return profileHash.get(); }
  std::unique_ptr<std::unordered_map<std::string, ProfileData>> endProfile();
342

343
  //----- transparency groups and soft masks
344
  virtual GBool checkTransparencyGroup(GfxState * /*state*/, GBool /*knockout*/) { return gTrue; }
345 346 347 348 349 350 351 352 353 354 355
  virtual void beginTransparencyGroup(GfxState * /*state*/, double * /*bbox*/,
				      GfxColorSpace * /*blendingColorSpace*/,
				      GBool /*isolated*/, GBool /*knockout*/,
				      GBool /*forSoftMask*/) {}
  virtual void endTransparencyGroup(GfxState * /*state*/) {}
  virtual void paintTransparencyGroup(GfxState * /*state*/, double * /*bbox*/) {}
  virtual void setSoftMask(GfxState * /*state*/, double * /*bbox*/, GBool /*alpha*/,
			   Function * /*transferFunc*/, GfxColor * /*backdropColor*/) {}
  virtual void clearSoftMask(GfxState * /*state*/) {}

  //----- links
356
  virtual void processLink(AnnotLink * /*link*/) {}
357 358 359 360 361 362

#if 1 //~tmp: turn off anti-aliasing temporarily
  virtual GBool getVectorAntialias() { return gFalse; }
  virtual void setVectorAntialias(GBool /*vaa*/) {}
#endif

363 364 365 366
#ifdef USE_CMS
  PopplerCache *getIccColorSpaceCache();
#endif

Kristian Høgsberg's avatar
Kristian Høgsberg committed
367 368 369 370
private:

  double defCTM[6];		// default coordinate transform matrix
  double defICTM[6];		// inverse of default CTM
371
  std::unique_ptr<std::unordered_map<std::string, ProfileData>> profileHash;
372 373 374 375

#ifdef USE_CMS
  PopplerCache iccColorSpaceCache;
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
376 377 378
};

#endif