PSOutputDev.h 22.9 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7
//========================================================================
//
// PSOutputDev.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
8 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
// Copyright (C) 2005 Martin Kretzschmar <martink@gnome.org>
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
18
// Copyright (C) 2006-2008, 2012, 2013, 2015, 2017 Albert Astals Cid <aacid@kde.org>
19
// Copyright (C) 2007 Brad Hards <bradh@kde.org>
20
// Copyright (C) 2009-2013 Thomas Freitag <Thomas.Freitag@alfa.de>
21
// Copyright (C) 2009 Till Kamppeter <till.kamppeter@gmail.com>
22
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
Albert Astals Cid's avatar
Albert Astals Cid committed
23
// Copyright (C) 2009, 2011, 2015-2017 William Bader <williambader@hotmail.com>
Albert Astals Cid's avatar
Albert Astals Cid committed
24
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
25
// Copyright (C) 2011, 2014, 2017 Adrian Johnson <ajohnson@redneon.com>
26
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
27
// 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
28
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
29
// Copyright (C) 2018 Philipp Knechtges <philipp-dev@knechtges.com>
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 42

#ifndef PSOUTPUTDEV_H
#define PSOUTPUTDEV_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

43
#include "poppler-config.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
44 45
#include <stddef.h>
#include "Object.h"
46
#include "GfxState.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
47 48
#include "GlobalParams.h"
#include "OutputDev.h"
49
#include <set>
50
#include <map>
51
#include <vector>
52 53 54
#include <unordered_set>
#include <unordered_map>
#include <string>
Kristian Høgsberg's avatar
Kristian Høgsberg committed
55

56 57 58
class PDFDoc;
class XRef;
class Function;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
59 60 61 62 63
class GfxPath;
class GfxFont;
class GfxColorSpace;
class GfxSeparationColorSpace;
class PDFRectangle;
64
struct PST1FontName;
65
struct PSFont8Info;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
66 67
struct PSFont16Enc;
class PSOutCustomColor;
68
class PSOutputDev;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
69 70 71 72 73 74 75 76

//------------------------------------------------------------------------
// PSOutputDev
//------------------------------------------------------------------------

enum PSOutMode {
  psModePS,
  psModeEPS,
77
  psModeForm
Kristian Høgsberg's avatar
Kristian Høgsberg committed
78 79 80 81 82 83 84 85 86
};

enum PSFileType {
  psFile,			// write to file
  psPipe,			// write to pipe
  psStdout,			// write to stdout
  psGeneric			// write to a generic stream
};

87 88 89 90 91
enum PSOutCustomCodeLocation {
  psOutCustomDocSetup,
  psOutCustomPageSetup
};

92
typedef void (*PSOutputFunc)(void *stream, const char *data, int len);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
93

94 95 96 97
typedef GooString *(*PSOutCustomCodeCbk)(PSOutputDev *psOut,
				       PSOutCustomCodeLocation loc, int n, 
				       void *data);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
98 99 100 101
class PSOutputDev: public OutputDev {
public:

  // Open a PostScript output file, and write the prolog.
102
  // pages has to be sorted in increasing order
103
  PSOutputDev(const char *fileName, PDFDoc *docA,
104
	      char *psTitleA,
105
	      const std::vector<int> &pages, PSOutMode modeA,
106
	      int paperWidthA = -1, int paperHeightA = -1,
107
              GBool noCrop = gFalse,
108
	      GBool duplexA = gTrue,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
109 110
	      int imgLLXA = 0, int imgLLYA = 0,
	      int imgURXA = 0, int imgURYA = 0,
111
	      GBool forceRasterizeA = gFalse,
112 113 114
	      GBool manualCtrlA = gFalse,
	      PSOutCustomCodeCbk customCodeCbkA = NULL,
	      void *customCodeCbkDataA = NULL);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
115 116

  // Open a PSOutputDev that will write to a generic stream.
117
  // pages has to be sorted in increasing order
Kristian Høgsberg's avatar
Kristian Høgsberg committed
118
  PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
119
	      char *psTitleA,
120
	      PDFDoc *docA,
121
	      const std::vector<int> &pages, PSOutMode modeA,
122
	      int paperWidthA = -1, int paperHeightA = -1,
123
              GBool noCrop = gFalse,
124
	      GBool duplexA = gTrue,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
125 126
	      int imgLLXA = 0, int imgLLYA = 0,
	      int imgURXA = 0, int imgURYA = 0,
127
	      GBool forceRasterizeA = gFalse,
128 129 130
	      GBool manualCtrlA = gFalse,
	      PSOutCustomCodeCbk customCodeCbkA = NULL,
	      void *customCodeCbkDataA = NULL);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
131 132 133 134 135 136 137 138 139 140 141

  // Destructor -- writes the trailer and closes the file.
  virtual ~PSOutputDev();

  // Check if file was successfully created.
  virtual GBool isOk() { return ok; }

  //---- 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.)
Albert Astals Cid's avatar
Albert Astals Cid committed
142
  GBool upsideDown() override { return gFalse; }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
143 144

  // Does this device use drawChar() or drawString()?
Albert Astals Cid's avatar
Albert Astals Cid committed
145
  GBool useDrawChar() override { return gFalse; }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
146

147 148 149
  // Does this device use tilingPatternFill()?  If this returns false,
  // tiling pattern fills will be reduced to a series of other drawing
  // operations.
Albert Astals Cid's avatar
Albert Astals Cid committed
150
  GBool useTilingPatternFill() override { return gTrue; }
151 152 153 154

  // Does this device use functionShadedFill(), axialShadedFill(), and
  // radialShadedFill()?  If this returns false, these shaded fills
  // will be reduced to a series of other drawing operations.
Albert Astals Cid's avatar
Albert Astals Cid committed
155
  GBool useShadedFills(int type) override
156
    { return (type < 4 && level >= psLevel2) || (type == 7 && level >= psLevel3); }
157 158 159

  // Does this device use drawForm()?  If this returns false,
  // form-type XObjects will be interpreted (i.e., unrolled).
Albert Astals Cid's avatar
Albert Astals Cid committed
160
  GBool useDrawForm() override { return preloadImagesForms; }
161

Kristian Høgsberg's avatar
Kristian Høgsberg committed
162 163
  // Does this device use beginType3Char/endType3Char?  Otherwise,
  // text in Type 3 fonts will be drawn with drawChar/drawString.
Albert Astals Cid's avatar
Albert Astals Cid committed
164
  GBool interpretType3Chars() override { return gFalse; }
165
  
Albert Astals Cid's avatar
Albert Astals Cid committed
166
  GBool needClipToCropBox() override { return mode == psModeEPS; }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
167 168 169 170

  //----- header/trailer (used only if manualCtrl is true)

  // Write the document-level header.
171
  void writeHeader(const std::vector<int> &pages,
172
		   PDFRectangle *mediaBox, PDFRectangle *cropBox,
173
		   int pageRotate, char *pstitle);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
174 175 176 177 178 179 180 181 182 183 184 185

  // Write the Xpdf procset.
  void writeXpdfProcset();

  // Write the trailer for the current page.
  void writePageTrailer();

  // Write the document trailer.
  void writeTrailer();

  //----- initialization and control

186 187 188 189
  // 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.
Albert Astals Cid's avatar
Albert Astals Cid committed
190
  GBool checkPageSlice(Page *page, double hDPI, double vDPI,
191 192
			       int rotate, GBool useMediaBox, GBool crop,
			       int sliceX, int sliceY, int sliceW, int sliceH,
193
			       GBool printing,
194
			       GBool (*abortCheckCbk)(void *data) = NULL,
195 196
			       void *abortCheckCbkData = NULL,
			       GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
Albert Astals Cid's avatar
Albert Astals Cid committed
197
			       void *annotDisplayDecideCbkData = NULL) override;
198

Kristian Høgsberg's avatar
Kristian Høgsberg committed
199
  // Start a page.
Albert Astals Cid's avatar
Albert Astals Cid committed
200
  void startPage(int pageNum, GfxState *state, XRef *xref) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
201 202

  // End a page.
Albert Astals Cid's avatar
Albert Astals Cid committed
203
  void endPage() override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
204 205

  //----- save/restore graphics state
Albert Astals Cid's avatar
Albert Astals Cid committed
206 207
  void saveState(GfxState *state) override;
  void restoreState(GfxState *state) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
208 209

  //----- update graphics state
Albert Astals Cid's avatar
Albert Astals Cid committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
  void updateCTM(GfxState *state, double m11, double m12,
			 double m21, double m22, double m31, double m32) override;
  void updateLineDash(GfxState *state) override;
  void updateFlatness(GfxState *state) override;
  void updateLineJoin(GfxState *state) override;
  void updateLineCap(GfxState *state) override;
  void updateMiterLimit(GfxState *state) override;
  void updateLineWidth(GfxState *state) override;
  void updateFillColorSpace(GfxState *state) override;
  void updateStrokeColorSpace(GfxState *state) override;
  void updateFillColor(GfxState *state) override;
  void updateStrokeColor(GfxState *state) override;
  void updateFillOverprint(GfxState *state) override;
  void updateStrokeOverprint(GfxState *state) override;
  void updateOverprintMode(GfxState *state) override;
  void updateTransfer(GfxState *state) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
226 227

  //----- update text state
Albert Astals Cid's avatar
Albert Astals Cid committed
228 229 230 231 232 233 234 235 236 237 238
  void updateFont(GfxState *state) override;
  void updateTextMat(GfxState *state) override;
  void updateCharSpace(GfxState *state) override;
  void updateRender(GfxState *state) override;
  void updateRise(GfxState *state) override;
  void updateWordSpace(GfxState *state) override;
  void updateHorizScaling(GfxState *state) override;
  void updateTextPos(GfxState *state) override;
  void updateTextShift(GfxState *state, double shift) override;
  void saveTextPos(GfxState *state) override;
  void restoreTextPos(GfxState *state) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
239 240

  //----- path painting
Albert Astals Cid's avatar
Albert Astals Cid committed
241 242 243 244
  void stroke(GfxState *state) override;
  void fill(GfxState *state) override;
  void eoFill(GfxState *state) override;
  GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
245
				  double *pmat, int paintType, int tilingType, Dict *resDict,
246 247
				  double *mat, double *bbox,
				  int x0, int y0, int x1, int y1,
Albert Astals Cid's avatar
Albert Astals Cid committed
248 249 250 251 252
				  double xStep, double yStep) override;
  GBool functionShadedFill(GfxState *state,
				   GfxFunctionShading *shading) override;
  GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double /*tMin*/, double /*tMax*/) override;
  GBool radialShadedFill(GfxState *state, GfxRadialShading *shading, double /*sMin*/, double /*sMax*/) override;
253
  GBool patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
254 255

  //----- path clipping
Albert Astals Cid's avatar
Albert Astals Cid committed
256 257 258
  void clip(GfxState *state) override;
  void eoClip(GfxState *state) override;
  void clipToStrokePath(GfxState *state) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
259 260

  //----- text drawing
261
  void drawString(GfxState *state, const GooString *s) override;
Albert Astals Cid's avatar
Albert Astals Cid committed
262 263
  void beginTextObject(GfxState *state) override;
  void endTextObject(GfxState *state) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
264 265

  //----- image drawing
Albert Astals Cid's avatar
Albert Astals Cid committed
266
  void drawImageMask(GfxState *state, Object *ref, Stream *str,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
267
			     int width, int height, GBool invert,
Albert Astals Cid's avatar
Albert Astals Cid committed
268 269
			     GBool interpolate, GBool inlineImg) override;
  void setSoftMaskFromImageMask(GfxState *state,
270 271
					Object *ref, Stream *str,
					int width, int height, GBool invert,
Albert Astals Cid's avatar
Albert Astals Cid committed
272 273 274
					GBool inlineImg, double *baseMatrix) override;
  void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) override;
  void drawImage(GfxState *state, Object *ref, Stream *str,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
275
			 int width, int height, GfxImageColorMap *colorMap,
Albert Astals Cid's avatar
Albert Astals Cid committed
276 277
			 GBool interpolate, int *maskColors, GBool inlineImg) override;
  void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
278 279
			       int width, int height,
			       GfxImageColorMap *colorMap,
280
			       GBool interpolate,
281
			       Stream *maskStr, int maskWidth, int maskHeight,
Albert Astals Cid's avatar
Albert Astals Cid committed
282
			       GBool maskInvert, GBool maskInterpolate) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
283

284
#ifdef OPI_SUPPORT
Kristian Høgsberg's avatar
Kristian Høgsberg committed
285
  //----- OPI functions
Albert Astals Cid's avatar
Albert Astals Cid committed
286 287
  void opiBegin(GfxState *state, Dict *opiDict) override;
  void opiEnd(GfxState *state, Dict *opiDict) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
288 289 290
#endif

  //----- Type 3 font operators
Albert Astals Cid's avatar
Albert Astals Cid committed
291 292 293
  void type3D0(GfxState *state, double wx, double wy) override;
  void type3D1(GfxState *state, double wx, double wy,
		       double llx, double lly, double urx, double ury) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
294

295
  //----- form XObjects
Albert Astals Cid's avatar
Albert Astals Cid committed
296
  void drawForm(Ref ref) override;
297

Kristian Høgsberg's avatar
Kristian Høgsberg committed
298
  //----- PostScript XObjects
Albert Astals Cid's avatar
Albert Astals Cid committed
299
  void psXObject(Stream *psStream, Stream *level1Stream) override;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315

  //----- miscellaneous
  void setOffset(double x, double y)
    { tx0 = x; ty0 = y; }
  void setScale(double x, double y)
    { xScale0 = x; yScale0 = y; }
  void setRotate(int rotateA)
    { rotate0 = rotateA; }
  void setClip(double llx, double lly, double urx, double ury)
    { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
  void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
		      void *data)
    { underlayCbk = cbk; underlayCbkData = data; }
  void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
		     void *data)
    { overlayCbk = cbk; overlayCbkData = data; }
316
  void setDisplayText(GBool display) { displayText = display; }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
317

318
  void setPSCenter(GBool center) { psCenter = center; }
319
  void setRasterAntialias(GBool a) { rasterAntialias = a; }
320 321
  void setRasterResolution(double r) { rasterResolution = r; }
  void setRasterMono(GBool b) { rasterMono = b; }
322
  void setUncompressPreloadedImages(GBool b) { uncompressPreloadedImages = b; }
323

324 325 326 327 328
  GBool getEmbedType1() const { return embedType1; }
  GBool getEmbedTrueType() const { return embedTrueType; }
  GBool getEmbedCIDPostScript() const { return embedCIDPostScript; }
  GBool getEmbedCIDTrueType() const { return embedCIDTrueType; }
  GBool getFontPassthrough() const { return fontPassthrough; }
329
  GBool getOptimizeColorSpace() const { return optimizeColorSpace; }
330
  GBool getPassLevel1CustomColor() const { return passLevel1CustomColor; }
331
  GBool getEnableLZW() const { return enableLZW; };
332
  GBool getEnableFlate() const
333
#ifdef ENABLE_ZLIB
334 335 336 337
    { return enableFlate; }
#else
    { return gFalse; }
#endif
338 339 340 341 342
  void setEmbedType1(GBool b) { embedType1 = b; }
  void setEmbedTrueType(GBool b) { embedTrueType = b; }
  void setEmbedCIDPostScript(GBool b) { embedCIDPostScript = b; }
  void setEmbedCIDTrueType(GBool b) { embedCIDTrueType = b; }
  void setFontPassthrough(GBool b) { fontPassthrough = b; }
343
  void setOptimizeColorSpace(GBool b) { optimizeColorSpace = b; }
344
  void setPassLevel1CustomColor(GBool b) { passLevel1CustomColor = b; }
345 346 347 348
  void setPreloadImagesForms(GBool b) { preloadImagesForms = b; }
  void setGenerateOPI(GBool b) { generateOPI = b; }
  void setUseASCIIHex(GBool b) { useASCIIHex = b; }
  void setUseBinary(GBool b) { useBinary = b; }
349
  void setEnableLZW(GBool b) { enableLZW = b; }
350
  void setEnableFlate(GBool b) { enableFlate = b; }
351

Kristian Høgsberg's avatar
Kristian Høgsberg committed
352 353 354
private:

  void init(PSOutputFunc outputFuncA, void *outputStreamA,
355
	    PSFileType fileTypeA, char *psTitleA, PDFDoc *doc,
356
	    const std::vector<int> &pages, PSOutMode modeA,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
357
	    int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
358
	    GBool manualCtrlA, int paperWidthA, int paperHeightA,
359
            GBool noCropA, GBool duplexA);
360
  void postInit();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
361 362 363 364
  void setupResources(Dict *resDict);
  void setupFonts(Dict *resDict);
  void setupFont(GfxFont *font, Dict *parentResDict);
  void setupEmbeddedType1Font(Ref *id, GooString *psName);
365
  void updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
366 367
  void setupExternalType1Font(GooString *fileName, GooString *psName);
  void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName);
368
  void setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
369
  void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName);
370 371
  void setupExternalTrueTypeFont(GfxFont *font, GooString *fileName,
				 GooString *psName);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
372
  void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName);
373 374
  void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName,
				    GBool needVerticalMetrics);
375 376 377 378
  void setupExternalCIDTrueTypeFont(GfxFont *font,
				    GooString *fileName,
				    GooString *psName,
				    GBool needVerticalMetrics);
379
  void setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString *psName);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
380
  void setupType3Font(GfxFont *font, GooString *psName, Dict *parentResDict);
381
  GooString *makePSFontName(GfxFont *font, const Ref *id);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
382
  void setupImages(Dict *resDict);
383
  void setupImage(Ref id, Stream *str, GBool mask);
384 385
  void setupForms(Dict *resDict);
  void setupForm(Ref id, Object *strObj);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
386 387 388
  void addProcessColor(double c, double m, double y, double k);
  void addCustomColor(GfxSeparationColorSpace *sepCS);
  void doPath(GfxPath *path);
389
  void maskToClippingPath(Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
390 391
  void doImageL1(Object *ref, GfxImageColorMap *colorMap,
		 GBool invert, GBool inlineImg,
392 393 394 395
		 Stream *str, int width, int height, int len,
		 int *maskColors, Stream *maskStr,
		 int maskWidth, int maskHeight, GBool maskInvert);
  void doImageL1Sep(Object *ref, GfxImageColorMap *colorMap,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
396
		    GBool invert, GBool inlineImg,
397 398 399
		    Stream *str, int width, int height, int len,
		    int *maskColors, Stream *maskStr,
		    int maskWidth, int maskHeight, GBool maskInvert);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
400 401
  void doImageL2(Object *ref, GfxImageColorMap *colorMap,
		 GBool invert, GBool inlineImg,
402 403 404
		 Stream *str, int width, int height, int len,
		 int *maskColors, Stream *maskStr,
		 int maskWidth, int maskHeight, GBool maskInvert);
405 406 407 408 409
  void doImageL3(Object *ref, GfxImageColorMap *colorMap,
		 GBool invert, GBool inlineImg,
		 Stream *str, int width, int height, int len,
		 int *maskColors, Stream *maskStr,
		 int maskWidth, int maskHeight, GBool maskInvert);
410
  void dumpColorSpaceL2(GfxColorSpace *colorSpace,
411 412
			GBool genXform, GBool updateColors,
			GBool map01);
413 414 415 416 417 418 419 420 421 422 423
  GBool tilingPatternFillL1(GfxState *state, Catalog *cat, Object *str,
			    double *pmat, int paintType, int tilingType, Dict *resDict,
			    double *mat, double *bbox,
			    int x0, int y0, int x1, int y1,
			    double xStep, double yStep);
  GBool tilingPatternFillL2(GfxState *state, Catalog *cat, Object *str,
			    double *pmat, int paintType, int tilingType, Dict *resDict,
			    double *mat, double *bbox,
			    int x0, int y0, int x1, int y1,
			    double xStep, double yStep);

424
#ifdef OPI_SUPPORT
Kristian Høgsberg's avatar
Kristian Høgsberg committed
425 426 427 428 429
  void opiBegin20(GfxState *state, Dict *dict);
  void opiBegin13(GfxState *state, Dict *dict);
  void opiTransform(GfxState *state, double x0, double y0,
		    double *x1, double *y1);
#endif
430
  void cvtFunction(Function *func, GBool invertPSFunction = gFalse);
431
  GooString *filterPSName(const GooString *name);
Hib Eris's avatar
Hib Eris committed
432 433

  // Write the document-level setup.
434
  void writeDocSetup(PDFDoc *doc, Catalog *catalog, const std::vector<int> &pages, GBool duplexA);
Hib Eris's avatar
Hib Eris committed
435

Kristian Høgsberg's avatar
Kristian Høgsberg committed
436
  void writePSChar(char c);
437 438
  void writePS(const char *s);
  void writePSBuf(const char *s, int len);
439
  void writePSFmt(const char *fmt, ...);
440
  void writePSString(const GooString *s);
441
  void writePSName(const char *s);
442
  GooString *filterPSLabel(GooString *label, GBool *needParens=nullptr);
443
  void writePSTextLine(const GooString *s);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
444 445 446 447 448

  PSLevel level;		// PostScript level (1, 2, separation)
  PSOutMode mode;		// PostScript mode (PS, EPS, form)
  int paperWidth;		// width of paper, in pts
  int paperHeight;		// height of paper, in pts
449
  GBool paperMatch;		// true if paper size is set to match each page
450 451 452 453
  int prevWidth;		// width of previous page
                                // (only psModePSOrigPageSizes output mode)
  int prevHeight;		// height of previous page
                                // (only psModePSOrigPageSizes output mode)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
454 455
  int imgLLX, imgLLY,		// imageable area, in pts
      imgURX, imgURY;
456
  GBool noCrop;
457 458 459 460
  GBool duplex;
  std::vector<int> pages;
  char *psTitle;
  GBool postInitDone;		// true if postInit() was called
Kristian Høgsberg's avatar
Kristian Høgsberg committed
461 462 463 464 465 466 467 468 469 470

  PSOutputFunc outputFunc;
  void *outputStream;
  PSFileType fileType;		// file / pipe / stdout
  GBool manualCtrl;
  int seqPage;			// current sequential page number
  void (*underlayCbk)(PSOutputDev *psOut, void *data);
  void *underlayCbkData;
  void (*overlayCbk)(PSOutputDev *psOut, void *data);
  void *overlayCbkData;
471 472 473 474
  GooString *(*customCodeCbk)(PSOutputDev *psOut,
			    PSOutCustomCodeLocation loc, int n, 
			    void *data);
  void *customCodeCbkData;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
475

476
  PDFDoc *doc;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
477 478 479 480 481
  XRef *xref;			// the xref table for this PDF file

  Ref *fontIDs;			// list of object IDs of all used fonts
  int fontIDLen;		// number of entries in fontIDs array
  int fontIDSize;		// size of fontIDs array
482
  std::set<int> resourceIDs;	// list of object IDs of objects containing Resources we've already set up
483 484
  std::unordered_set<std::string> fontNames; // all used font names
  std::unordered_map<std::string, int> fontMaxValidGlyph; // max valid glyph of each font
485 486 487
  PST1FontName *t1FontNames;	// font names for Type 1/1C fonts
  int t1FontNameLen;		// number of entries in t1FontNames array
  int t1FontNameSize;		// size of t1FontNames array
488 489 490
  PSFont8Info *font8Info;	// info for 8-bit fonts
  int font8InfoLen;		// number of entries in font8Info array
  int font8InfoSize;		// size of font8Info array
Kristian Høgsberg's avatar
Kristian Høgsberg committed
491 492 493
  PSFont16Enc *font16Enc;	// encodings for substitute 16-bit fonts
  int font16EncLen;		// number of entries in font16Enc array
  int font16EncSize;		// size of font16Enc array
494 495 496 497 498 499
  Ref *imgIDs;			// list of image IDs for in-memory images
  int imgIDLen;			// number of entries in imgIDs array
  int imgIDSize;		// size of imgIDs array
  Ref *formIDs;			// list of IDs for predefined forms
  int formIDLen;		// number of entries in formIDs array
  int formIDSize;		// size of formIDs array
Kristian Høgsberg's avatar
Kristian Høgsberg committed
500
  int numSaves;			// current number of gsaves
501 502
  int numTilingPatterns;	// current number of nested tiling patterns
  int nextFunc;			// next unique number to use for a function
Kristian Høgsberg's avatar
Kristian Høgsberg committed
503

504 505
  GooList *paperSizes;		// list of used paper sizes, if paperMatch
				//   is true [PSOutPaperSize]
506
  std::map<int,int> pagePaperSize; // page num to paperSize entry mapping
Kristian Høgsberg's avatar
Kristian Høgsberg committed
507 508 509 510 511 512 513 514
  double tx0, ty0;		// global translation
  double xScale0, yScale0;	// global scaling
  int rotate0;			// rotation angle (0, 90, 180, 270)
  double clipLLX0, clipLLY0,
         clipURX0, clipURY0;
  double tx, ty;		// global translation for current page
  double xScale, yScale;	// global scaling for current page
  int rotate;			// rotation angle for current page
515 516
  double epsX1, epsY1,		// EPS bounding box (unrotated)
         epsX2, epsY2;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
517 518 519 520 521 522 523 524 525 526 527

  GooString *embFontList;		// resource comments for embedded fonts

  int processColors;		// used process colors
  PSOutCustomColor		// used custom colors
    *customColors;

  GBool haveTextClip;		// set if text has been drawn with a
				//   clipping render mode

  GBool inType3Char;		// inside a Type 3 CharProc
528
  GBool inUncoloredPattern;     // inside a uncolored pattern (PaintType = 2)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
529 530 531
  GooString *t3String;		// Type 3 content string
  double t3WX, t3WY,		// Type 3 character parameters
         t3LLX, t3LLY, t3URX, t3URY;
532
  GBool t3FillColorOnly;	// operators should only use the fill color
Kristian Høgsberg's avatar
Kristian Høgsberg committed
533
  GBool t3Cacheable;		// cleared if char is not cacheable
534
  GBool t3NeedsRestore;		// set if a 'q' operator was issued
535
  GBool forceRasterize;		// forces the page to be rasterized into a image before printing
536
  GBool displayText;		// displayText
537
  GBool psCenter;		// center pages on the paper
538
  GBool rasterAntialias;	// antialias on rasterize
539
  GBool uncompressPreloadedImages;
540 541 542 543
  double rasterResolution;	// PostScript rasterization resolution (dpi)
  GBool rasterMono;		// true to do PostScript rasterization
				//   in monochrome (gray); false to do it
				//   in color (RGB/CMYK)
544 545 546 547 548
  GBool embedType1;		// embed Type 1 fonts?
  GBool embedTrueType;		// embed TrueType fonts?
  GBool embedCIDPostScript;	// embed CID PostScript fonts?
  GBool embedCIDTrueType;	// embed CID TrueType fonts?
  GBool fontPassthrough;	// pass all fonts through as-is?
549 550
  GBool optimizeColorSpace;	// false to keep gray RGB images in their original color space
				// true to optimize gray images to DeviceGray color space
551 552 553
  GBool passLevel1CustomColor;	// false to convert all custom colors to CMYK
				// true to pass custom colors
				// has effect only when doing a level1sep
554 555 556 557 558
  GBool preloadImagesForms;	// preload PostScript images and forms into
				//   memory
  GBool generateOPI;		// generate PostScript OPI comments?
  GBool useASCIIHex;		// use ASCIIHex instead of ASCII85?
  GBool useBinary;		// use binary instead of hex
559
  GBool enableLZW;		// enable LZW compression
560
  GBool enableFlate;		// enable Flate compression
Kristian Høgsberg's avatar
Kristian Høgsberg committed
561

562
#ifdef OPI_SUPPORT
Kristian Høgsberg's avatar
Kristian Høgsberg committed
563 564 565 566 567 568 569 570 571 572
  int opi13Nest;		// nesting level of OPI 1.3 objects
  int opi20Nest;		// nesting level of OPI 2.0 objects
#endif

  GBool ok;			// set up ok?

  friend class WinPDFPrinter;
};

#endif