beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / PSOutputDev.h
blob7318cafdf2a357457bb0445b26fed55c0770466f
1 //========================================================================
2 //
3 // PSOutputDev.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2005 Martin Kretzschmar <martink@gnome.org>
17 // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
18 // Copyright (C) 2006-2008, 2012, 2013, 2015 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>
23 // Copyright (C) 2009, 2011, 2015 William Bader <williambader@hotmail.com>
24 // Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
25 // Copyright (C) 2011, 2014 Adrian Johnson <ajohnson@redneon.com>
26 // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
28 // To see a description of the changes please see the Changelog file that
29 // came with your tarball or type make ChangeLog if you are building from git
31 //========================================================================
33 #ifndef PSOUTPUTDEV_H
34 #define PSOUTPUTDEV_H
36 #ifdef USE_GCC_PRAGMAS
37 #pragma interface
38 #endif
40 #include "poppler-config.h"
41 #include <stddef.h>
42 #include "Object.h"
43 #include "GfxState.h"
44 #include "GlobalParams.h"
45 #include "OutputDev.h"
46 #include <set>
47 #include <map>
48 #include <vector>
50 class GHooash;
51 class PDFDoc;
52 class XRef;
53 class Function;
54 class GfxPath;
55 class GfxFont;
56 class GfxColorSpace;
57 class GfxSeparationColorSpace;
58 class PDFRectangle;
59 struct PST1FontName;
60 struct PSFont8Info;
61 struct PSFont16Enc;
62 class PSOutCustomColor;
63 class PSOutputDev;
65 //------------------------------------------------------------------------
66 // PSOutputDev
67 //------------------------------------------------------------------------
69 enum PSOutMode {
70 psModePS,
71 psModeEPS,
72 psModeForm
75 enum PSFileType {
76 psFile, // write to file
77 psPipe, // write to pipe
78 psStdout, // write to stdout
79 psGeneric // write to a generic stream
82 enum PSOutCustomCodeLocation {
83 psOutCustomDocSetup,
84 psOutCustomPageSetup
87 typedef void (*PSOutputFunc)(void *stream, const char *data, int len);
89 typedef GooString *(*PSOutCustomCodeCbk)(PSOutputDev *psOut,
90 PSOutCustomCodeLocation loc, int n,
91 void *data);
93 class PSOutputDev: public OutputDev {
94 public:
96 // Open a PostScript output file, and write the prolog.
97 // pages has to be sorted in increasing order
98 PSOutputDev(const char *fileName, PDFDoc *docA,
99 char *psTitleA,
100 const std::vector<int> &pages, PSOutMode modeA,
101 int paperWidthA = -1, int paperHeightA = -1,
102 GBool noCrop = gFalse,
103 GBool duplexA = gTrue,
104 int imgLLXA = 0, int imgLLYA = 0,
105 int imgURXA = 0, int imgURYA = 0,
106 GBool forceRasterizeA = gFalse,
107 GBool manualCtrlA = gFalse,
108 PSOutCustomCodeCbk customCodeCbkA = NULL,
109 void *customCodeCbkDataA = NULL);
111 // Open a PSOutputDev that will write to a generic stream.
112 // pages has to be sorted in increasing order
113 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
114 char *psTitleA,
115 PDFDoc *docA,
116 const std::vector<int> &pages, PSOutMode modeA,
117 int paperWidthA = -1, int paperHeightA = -1,
118 GBool noCrop = gFalse,
119 GBool duplexA = gTrue,
120 int imgLLXA = 0, int imgLLYA = 0,
121 int imgURXA = 0, int imgURYA = 0,
122 GBool forceRasterizeA = gFalse,
123 GBool manualCtrlA = gFalse,
124 PSOutCustomCodeCbk customCodeCbkA = NULL,
125 void *customCodeCbkDataA = NULL);
127 // Destructor -- writes the trailer and closes the file.
128 virtual ~PSOutputDev();
130 // Check if file was successfully created.
131 virtual GBool isOk() { return ok; }
133 //---- get info about output device
135 // Does this device use upside-down coordinates?
136 // (Upside-down means (0,0) is the top left corner of the page.)
137 virtual GBool upsideDown() { return gFalse; }
139 // Does this device use drawChar() or drawString()?
140 virtual GBool useDrawChar() { return gFalse; }
142 // Does this device use tilingPatternFill()? If this returns false,
143 // tiling pattern fills will be reduced to a series of other drawing
144 // operations.
145 virtual GBool useTilingPatternFill() { return gTrue; }
147 // Does this device use functionShadedFill(), axialShadedFill(), and
148 // radialShadedFill()? If this returns false, these shaded fills
149 // will be reduced to a series of other drawing operations.
150 virtual GBool useShadedFills(int type)
151 { return type < 4 && level >= psLevel2; }
153 // Does this device use drawForm()? If this returns false,
154 // form-type XObjects will be interpreted (i.e., unrolled).
155 virtual GBool useDrawForm() { return preloadImagesForms; }
157 // Does this device use beginType3Char/endType3Char? Otherwise,
158 // text in Type 3 fonts will be drawn with drawChar/drawString.
159 virtual GBool interpretType3Chars() { return gFalse; }
161 virtual GBool needClipToCropBox() { return mode == psModeEPS; }
163 //----- header/trailer (used only if manualCtrl is true)
165 // Write the document-level header.
166 void writeHeader(const std::vector<int> &pages,
167 PDFRectangle *mediaBox, PDFRectangle *cropBox,
168 int pageRotate, char *pstitle);
170 // Write the Xpdf procset.
171 void writeXpdfProcset();
173 // Write the trailer for the current page.
174 void writePageTrailer();
176 // Write the document trailer.
177 void writeTrailer();
179 //----- initialization and control
181 // Check to see if a page slice should be displayed. If this
182 // returns false, the page display is aborted. Typically, an
183 // OutputDev will use some alternate means to display the page
184 // before returning false.
185 virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
186 int rotate, GBool useMediaBox, GBool crop,
187 int sliceX, int sliceY, int sliceW, int sliceH,
188 GBool printing,
189 GBool (*abortCheckCbk)(void *data) = NULL,
190 void *abortCheckCbkData = NULL,
191 GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
192 void *annotDisplayDecideCbkData = NULL);
194 // Start a page.
195 virtual void startPage(int pageNum, GfxState *state, XRef *xref);
197 // End a page.
198 virtual void endPage();
200 //----- save/restore graphics state
201 virtual void saveState(GfxState *state);
202 virtual void restoreState(GfxState *state);
204 //----- update graphics state
205 virtual void updateCTM(GfxState *state, double m11, double m12,
206 double m21, double m22, double m31, double m32);
207 virtual void updateLineDash(GfxState *state);
208 virtual void updateFlatness(GfxState *state);
209 virtual void updateLineJoin(GfxState *state);
210 virtual void updateLineCap(GfxState *state);
211 virtual void updateMiterLimit(GfxState *state);
212 virtual void updateLineWidth(GfxState *state);
213 virtual void updateFillColorSpace(GfxState *state);
214 virtual void updateStrokeColorSpace(GfxState *state);
215 virtual void updateFillColor(GfxState *state);
216 virtual void updateStrokeColor(GfxState *state);
217 virtual void updateFillOverprint(GfxState *state);
218 virtual void updateStrokeOverprint(GfxState *state);
219 virtual void updateOverprintMode(GfxState *state);
220 virtual void updateTransfer(GfxState *state);
222 //----- update text state
223 virtual void updateFont(GfxState *state);
224 virtual void updateTextMat(GfxState *state);
225 virtual void updateCharSpace(GfxState *state);
226 virtual void updateRender(GfxState *state);
227 virtual void updateRise(GfxState *state);
228 virtual void updateWordSpace(GfxState *state);
229 virtual void updateHorizScaling(GfxState *state);
230 virtual void updateTextPos(GfxState *state);
231 virtual void updateTextShift(GfxState *state, double shift);
232 virtual void saveTextPos(GfxState *state);
233 virtual void restoreTextPos(GfxState *state);
235 //----- path painting
236 virtual void stroke(GfxState *state);
237 virtual void fill(GfxState *state);
238 virtual void eoFill(GfxState *state);
239 virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
240 double *pmat, int paintType, int tilingType, Dict *resDict,
241 double *mat, double *bbox,
242 int x0, int y0, int x1, int y1,
243 double xStep, double yStep);
244 virtual GBool functionShadedFill(GfxState *state,
245 GfxFunctionShading *shading);
246 virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double /*tMin*/, double /*tMax*/);
247 virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading, double /*sMin*/, double /*sMax*/);
249 //----- path clipping
250 virtual void clip(GfxState *state);
251 virtual void eoClip(GfxState *state);
252 virtual void clipToStrokePath(GfxState *state);
254 //----- text drawing
255 virtual void drawString(GfxState *state, GooString *s);
256 virtual void beginTextObject(GfxState *state);
257 virtual void endTextObject(GfxState *state);
259 //----- image drawing
260 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
261 int width, int height, GBool invert,
262 GBool interpolate, GBool inlineImg);
263 virtual void setSoftMaskFromImageMask(GfxState *state,
264 Object *ref, Stream *str,
265 int width, int height, GBool invert,
266 GBool inlineImg, double *baseMatrix);
267 virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
268 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
269 int width, int height, GfxImageColorMap *colorMap,
270 GBool interpolate, int *maskColors, GBool inlineImg);
271 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
272 int width, int height,
273 GfxImageColorMap *colorMap,
274 GBool interpolate,
275 Stream *maskStr, int maskWidth, int maskHeight,
276 GBool maskInvert, GBool maskInterpolate);
278 #if OPI_SUPPORT
279 //----- OPI functions
280 virtual void opiBegin(GfxState *state, Dict *opiDict);
281 virtual void opiEnd(GfxState *state, Dict *opiDict);
282 #endif
284 //----- Type 3 font operators
285 virtual void type3D0(GfxState *state, double wx, double wy);
286 virtual void type3D1(GfxState *state, double wx, double wy,
287 double llx, double lly, double urx, double ury);
289 //----- form XObjects
290 virtual void drawForm(Ref ref);
292 //----- PostScript XObjects
293 virtual void psXObject(Stream *psStream, Stream *level1Stream);
295 //----- miscellaneous
296 void setOffset(double x, double y)
297 { tx0 = x; ty0 = y; }
298 void setScale(double x, double y)
299 { xScale0 = x; yScale0 = y; }
300 void setRotate(int rotateA)
301 { rotate0 = rotateA; }
302 void setClip(double llx, double lly, double urx, double ury)
303 { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
304 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
305 void *data)
306 { underlayCbk = cbk; underlayCbkData = data; }
307 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
308 void *data)
309 { overlayCbk = cbk; overlayCbkData = data; }
310 void setDisplayText(GBool display) { displayText = display; }
312 void setRasterAntialias(GBool a) { rasterAntialias = a; }
313 void setRasterResolution(double r) { rasterResolution = r; }
314 void setRasterMono(GBool b) { rasterMono = b; }
315 void setUncompressPreloadedImages(GBool b) { uncompressPreloadedImages = b; }
317 GBool getEmbedType1() const { return embedType1; }
318 GBool getEmbedTrueType() const { return embedTrueType; }
319 GBool getEmbedCIDPostScript() const { return embedCIDPostScript; }
320 GBool getEmbedCIDTrueType() const { return embedCIDTrueType; }
321 GBool getFontPassthrough() const { return fontPassthrough; }
322 GBool getOptimizeColorSpace() const { return optimizeColorSpace; }
323 void setEmbedType1(GBool b) { embedType1 = b; }
324 void setEmbedTrueType(GBool b) { embedTrueType = b; }
325 void setEmbedCIDPostScript(GBool b) { embedCIDPostScript = b; }
326 void setEmbedCIDTrueType(GBool b) { embedCIDTrueType = b; }
327 void setFontPassthrough(GBool b) { fontPassthrough = b; }
328 void setOptimizeColorSpace(GBool b) { optimizeColorSpace = b; }
329 void setPreloadImagesForms(GBool b) { preloadImagesForms = b; }
330 void setGenerateOPI(GBool b) { generateOPI = b; }
331 void setUseASCIIHex(GBool b) { useASCIIHex = b; }
332 void setUseBinary(GBool b) { useBinary = b; }
334 private:
336 void init(PSOutputFunc outputFuncA, void *outputStreamA,
337 PSFileType fileTypeA, char *psTitleA, PDFDoc *doc,
338 const std::vector<int> &pages, PSOutMode modeA,
339 int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
340 GBool manualCtrlA, int paperWidthA, int paperHeightA,
341 GBool noCropA, GBool duplexA);
342 void postInit();
343 void setupResources(Dict *resDict);
344 void setupFonts(Dict *resDict);
345 void setupFont(GfxFont *font, Dict *parentResDict);
346 void setupEmbeddedType1Font(Ref *id, GooString *psName);
347 void setupExternalType1Font(GooString *fileName, GooString *psName);
348 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName);
349 void setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName);
350 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName);
351 void setupExternalTrueTypeFont(GfxFont *font, GooString *fileName,
352 GooString *psName);
353 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName);
354 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName,
355 GBool needVerticalMetrics);
356 void setupExternalCIDTrueTypeFont(GfxFont *font,
357 GooString *fileName,
358 GooString *psName,
359 GBool needVerticalMetrics);
360 void setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString *psName);
361 void setupType3Font(GfxFont *font, GooString *psName, Dict *parentResDict);
362 GooString *makePSFontName(GfxFont *font, Ref *id);
363 void setupImages(Dict *resDict);
364 void setupImage(Ref id, Stream *str, GBool mask);
365 void setupForms(Dict *resDict);
366 void setupForm(Ref id, Object *strObj);
367 void addProcessColor(double c, double m, double y, double k);
368 void addCustomColor(GfxSeparationColorSpace *sepCS);
369 void doPath(GfxPath *path);
370 void maskToClippingPath(Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert);
371 void doImageL1(Object *ref, GfxImageColorMap *colorMap,
372 GBool invert, GBool inlineImg,
373 Stream *str, int width, int height, int len,
374 int *maskColors, Stream *maskStr,
375 int maskWidth, int maskHeight, GBool maskInvert);
376 void doImageL1Sep(Object *ref, GfxImageColorMap *colorMap,
377 GBool invert, GBool inlineImg,
378 Stream *str, int width, int height, int len,
379 int *maskColors, Stream *maskStr,
380 int maskWidth, int maskHeight, GBool maskInvert);
381 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
382 GBool invert, GBool inlineImg,
383 Stream *str, int width, int height, int len,
384 int *maskColors, Stream *maskStr,
385 int maskWidth, int maskHeight, GBool maskInvert);
386 void doImageL3(Object *ref, GfxImageColorMap *colorMap,
387 GBool invert, GBool inlineImg,
388 Stream *str, int width, int height, int len,
389 int *maskColors, Stream *maskStr,
390 int maskWidth, int maskHeight, GBool maskInvert);
391 void dumpColorSpaceL2(GfxColorSpace *colorSpace,
392 GBool genXform, GBool updateColors,
393 GBool map01);
394 GBool tilingPatternFillL1(GfxState *state, Catalog *cat, Object *str,
395 double *pmat, int paintType, int tilingType, Dict *resDict,
396 double *mat, double *bbox,
397 int x0, int y0, int x1, int y1,
398 double xStep, double yStep);
399 GBool tilingPatternFillL2(GfxState *state, Catalog *cat, Object *str,
400 double *pmat, int paintType, int tilingType, Dict *resDict,
401 double *mat, double *bbox,
402 int x0, int y0, int x1, int y1,
403 double xStep, double yStep);
405 #if OPI_SUPPORT
406 void opiBegin20(GfxState *state, Dict *dict);
407 void opiBegin13(GfxState *state, Dict *dict);
408 void opiTransform(GfxState *state, double x0, double y0,
409 double *x1, double *y1);
410 #endif
411 void cvtFunction(Function *func, GBool invertPSFunction = gFalse);
412 GooString *filterPSName(GooString *name);
414 // Write the document-level setup.
415 void writeDocSetup(PDFDoc *doc, Catalog *catalog, const std::vector<int> &pages, GBool duplexA);
417 void writePSChar(char c);
418 void writePS(const char *s);
419 void writePSBuf(const char *s, int len);
420 void writePSFmt(const char *fmt, ...);
421 void writePSString(GooString *s);
422 void writePSName(const char *s);
423 GooString *filterPSLabel(GooString *label, GBool *needParens=0);
424 void writePSTextLine(GooString *s);
426 PSLevel level; // PostScript level (1, 2, separation)
427 PSOutMode mode; // PostScript mode (PS, EPS, form)
428 int paperWidth; // width of paper, in pts
429 int paperHeight; // height of paper, in pts
430 GBool paperMatch; // true if paper size is set to match each page
431 int prevWidth; // width of previous page
432 // (only psModePSOrigPageSizes output mode)
433 int prevHeight; // height of previous page
434 // (only psModePSOrigPageSizes output mode)
435 int imgLLX, imgLLY, // imageable area, in pts
436 imgURX, imgURY;
437 GBool noCrop;
438 GBool duplex;
439 std::vector<int> pages;
440 char *psTitle;
441 GBool postInitDone; // true if postInit() was called
443 PSOutputFunc outputFunc;
444 void *outputStream;
445 PSFileType fileType; // file / pipe / stdout
446 GBool manualCtrl;
447 int seqPage; // current sequential page number
448 void (*underlayCbk)(PSOutputDev *psOut, void *data);
449 void *underlayCbkData;
450 void (*overlayCbk)(PSOutputDev *psOut, void *data);
451 void *overlayCbkData;
452 GooString *(*customCodeCbk)(PSOutputDev *psOut,
453 PSOutCustomCodeLocation loc, int n,
454 void *data);
455 void *customCodeCbkData;
457 PDFDoc *doc;
458 XRef *xref; // the xref table for this PDF file
460 Ref *fontIDs; // list of object IDs of all used fonts
461 int fontIDLen; // number of entries in fontIDs array
462 int fontIDSize; // size of fontIDs array
463 std::set<int> resourceIDs; // list of object IDs of objects containing Resources we've already set up
464 GooHash *fontNames; // all used font names
465 PST1FontName *t1FontNames; // font names for Type 1/1C fonts
466 int t1FontNameLen; // number of entries in t1FontNames array
467 int t1FontNameSize; // size of t1FontNames array
468 PSFont8Info *font8Info; // info for 8-bit fonts
469 int font8InfoLen; // number of entries in font8Info array
470 int font8InfoSize; // size of font8Info array
471 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
472 int font16EncLen; // number of entries in font16Enc array
473 int font16EncSize; // size of font16Enc array
474 Ref *imgIDs; // list of image IDs for in-memory images
475 int imgIDLen; // number of entries in imgIDs array
476 int imgIDSize; // size of imgIDs array
477 Ref *formIDs; // list of IDs for predefined forms
478 int formIDLen; // number of entries in formIDs array
479 int formIDSize; // size of formIDs array
480 int numSaves; // current number of gsaves
481 int numTilingPatterns; // current number of nested tiling patterns
482 int nextFunc; // next unique number to use for a function
484 GooList *paperSizes; // list of used paper sizes, if paperMatch
485 // is true [PSOutPaperSize]
486 std::map<int,int> pagePaperSize; // page num to paperSize entry mapping
487 double tx0, ty0; // global translation
488 double xScale0, yScale0; // global scaling
489 int rotate0; // rotation angle (0, 90, 180, 270)
490 double clipLLX0, clipLLY0,
491 clipURX0, clipURY0;
492 double tx, ty; // global translation for current page
493 double xScale, yScale; // global scaling for current page
494 int rotate; // rotation angle for current page
495 double epsX1, epsY1, // EPS bounding box (unrotated)
496 epsX2, epsY2;
498 GooString *embFontList; // resource comments for embedded fonts
500 int processColors; // used process colors
501 PSOutCustomColor // used custom colors
502 *customColors;
504 GBool haveTextClip; // set if text has been drawn with a
505 // clipping render mode
507 GBool inType3Char; // inside a Type 3 CharProc
508 GBool inUncoloredPattern; // inside a uncolored pattern (PaintType = 2)
509 GooString *t3String; // Type 3 content string
510 double t3WX, t3WY, // Type 3 character parameters
511 t3LLX, t3LLY, t3URX, t3URY;
512 GBool t3FillColorOnly; // operators should only use the fill color
513 GBool t3Cacheable; // cleared if char is not cacheable
514 GBool t3NeedsRestore; // set if a 'q' operator was issued
515 GBool forceRasterize; // forces the page to be rasterized into a image before printing
516 GBool displayText; // displayText
517 GBool rasterAntialias; // antialias on rasterize
518 GBool uncompressPreloadedImages;
519 double rasterResolution; // PostScript rasterization resolution (dpi)
520 GBool rasterMono; // true to do PostScript rasterization
521 // in monochrome (gray); false to do it
522 // in color (RGB/CMYK)
523 GBool embedType1; // embed Type 1 fonts?
524 GBool embedTrueType; // embed TrueType fonts?
525 GBool embedCIDPostScript; // embed CID PostScript fonts?
526 GBool embedCIDTrueType; // embed CID TrueType fonts?
527 GBool fontPassthrough; // pass all fonts through as-is?
528 GBool optimizeColorSpace; // false to keep gray RGB images in their original color space
529 // true to optimize gray images to DeviceGray color space
530 GBool preloadImagesForms; // preload PostScript images and forms into
531 // memory
532 GBool generateOPI; // generate PostScript OPI comments?
533 GBool useASCIIHex; // use ASCIIHex instead of ASCII85?
534 GBool useBinary; // use binary instead of hex
536 #if OPI_SUPPORT
537 int opi13Nest; // nesting level of OPI 1.3 objects
538 int opi20Nest; // nesting level of OPI 2.0 objects
539 #endif
541 GBool ok; // set up ok?
543 friend class WinPDFPrinter;
546 #endif