fix permissions
[luatex.git] / source / libs / poppler / poppler-0.28.0 / poppler / PSOutputDev.h
blobf30204deeb59f0b50a93d42c7caf25fca0c3bbe6
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 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 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>
49 class GHooash;
50 class PDFDoc;
51 class XRef;
52 class Function;
53 class GfxPath;
54 class GfxFont;
55 class GfxColorSpace;
56 class GfxSeparationColorSpace;
57 class PDFRectangle;
58 struct PST1FontName;
59 struct PSFont8Info;
60 struct PSFont16Enc;
61 class PSOutCustomColor;
62 class PSOutputDev;
64 //------------------------------------------------------------------------
65 // PSOutputDev
66 //------------------------------------------------------------------------
68 enum PSOutMode {
69 psModePS,
70 psModeEPS,
71 psModeForm
74 enum PSFileType {
75 psFile, // write to file
76 psPipe, // write to pipe
77 psStdout, // write to stdout
78 psGeneric // write to a generic stream
81 enum PSOutCustomCodeLocation {
82 psOutCustomDocSetup,
83 psOutCustomPageSetup
86 typedef void (*PSOutputFunc)(void *stream, const char *data, int len);
88 typedef GooString *(*PSOutCustomCodeCbk)(PSOutputDev *psOut,
89 PSOutCustomCodeLocation loc, int n,
90 void *data);
92 class PSOutputDev: public OutputDev {
93 public:
95 // Open a PostScript output file, and write the prolog.
96 PSOutputDev(const char *fileName, PDFDoc *docA,
97 char *psTitle,
98 int firstPage, int lastPage, PSOutMode modeA,
99 int paperWidthA = -1, int paperHeightA = -1,
100 GBool noCrop = gFalse,
101 GBool duplexA = gTrue,
102 int imgLLXA = 0, int imgLLYA = 0,
103 int imgURXA = 0, int imgURYA = 0,
104 GBool forceRasterizeA = gFalse,
105 GBool manualCtrlA = gFalse,
106 PSOutCustomCodeCbk customCodeCbkA = NULL,
107 void *customCodeCbkDataA = NULL);
109 // Open a PSOutputDev that will write to a generic stream.
110 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
111 char *psTitle,
112 PDFDoc *docA,
113 int firstPage, int lastPage, PSOutMode modeA,
114 int paperWidthA = -1, int paperHeightA = -1,
115 GBool noCrop = gFalse,
116 GBool duplexA = gTrue,
117 int imgLLXA = 0, int imgLLYA = 0,
118 int imgURXA = 0, int imgURYA = 0,
119 GBool forceRasterizeA = gFalse,
120 GBool manualCtrlA = gFalse,
121 PSOutCustomCodeCbk customCodeCbkA = NULL,
122 void *customCodeCbkDataA = NULL);
124 // Destructor -- writes the trailer and closes the file.
125 virtual ~PSOutputDev();
127 // Check if file was successfully created.
128 virtual GBool isOk() { return ok; }
130 //---- get info about output device
132 // Does this device use upside-down coordinates?
133 // (Upside-down means (0,0) is the top left corner of the page.)
134 virtual GBool upsideDown() { return gFalse; }
136 // Does this device use drawChar() or drawString()?
137 virtual GBool useDrawChar() { return gFalse; }
139 // Does this device use tilingPatternFill()? If this returns false,
140 // tiling pattern fills will be reduced to a series of other drawing
141 // operations.
142 virtual GBool useTilingPatternFill() { return gTrue; }
144 // Does this device use functionShadedFill(), axialShadedFill(), and
145 // radialShadedFill()? If this returns false, these shaded fills
146 // will be reduced to a series of other drawing operations.
147 virtual GBool useShadedFills(int type)
148 { return type < 4 && level >= psLevel2; }
150 // Does this device use drawForm()? If this returns false,
151 // form-type XObjects will be interpreted (i.e., unrolled).
152 virtual GBool useDrawForm() { return preload; }
154 // Does this device use beginType3Char/endType3Char? Otherwise,
155 // text in Type 3 fonts will be drawn with drawChar/drawString.
156 virtual GBool interpretType3Chars() { return gFalse; }
158 virtual GBool needClipToCropBox() { return mode == psModeEPS; }
160 //----- header/trailer (used only if manualCtrl is true)
162 // Write the document-level header.
163 void writeHeader(int firstPage, int lastPage,
164 PDFRectangle *mediaBox, PDFRectangle *cropBox,
165 int pageRotate, char *pstitle);
167 // Write the Xpdf procset.
168 void writeXpdfProcset();
170 // Write the trailer for the current page.
171 void writePageTrailer();
173 // Write the document trailer.
174 void writeTrailer();
176 //----- initialization and control
178 // Check to see if a page slice should be displayed. If this
179 // returns false, the page display is aborted. Typically, an
180 // OutputDev will use some alternate means to display the page
181 // before returning false.
182 virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
183 int rotate, GBool useMediaBox, GBool crop,
184 int sliceX, int sliceY, int sliceW, int sliceH,
185 GBool printing,
186 GBool (*abortCheckCbk)(void *data) = NULL,
187 void *abortCheckCbkData = NULL,
188 GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
189 void *annotDisplayDecideCbkData = NULL);
191 // Start a page.
192 virtual void startPage(int pageNum, GfxState *state, XRef *xref);
194 // End a page.
195 virtual void endPage();
197 //----- save/restore graphics state
198 virtual void saveState(GfxState *state);
199 virtual void restoreState(GfxState *state);
201 //----- update graphics state
202 virtual void updateCTM(GfxState *state, double m11, double m12,
203 double m21, double m22, double m31, double m32);
204 virtual void updateLineDash(GfxState *state);
205 virtual void updateFlatness(GfxState *state);
206 virtual void updateLineJoin(GfxState *state);
207 virtual void updateLineCap(GfxState *state);
208 virtual void updateMiterLimit(GfxState *state);
209 virtual void updateLineWidth(GfxState *state);
210 virtual void updateFillColorSpace(GfxState *state);
211 virtual void updateStrokeColorSpace(GfxState *state);
212 virtual void updateFillColor(GfxState *state);
213 virtual void updateStrokeColor(GfxState *state);
214 virtual void updateFillOverprint(GfxState *state);
215 virtual void updateStrokeOverprint(GfxState *state);
216 virtual void updateOverprintMode(GfxState *state);
217 virtual void updateTransfer(GfxState *state);
219 //----- update text state
220 virtual void updateFont(GfxState *state);
221 virtual void updateTextMat(GfxState *state);
222 virtual void updateCharSpace(GfxState *state);
223 virtual void updateRender(GfxState *state);
224 virtual void updateRise(GfxState *state);
225 virtual void updateWordSpace(GfxState *state);
226 virtual void updateHorizScaling(GfxState *state);
227 virtual void updateTextPos(GfxState *state);
228 virtual void updateTextShift(GfxState *state, double shift);
229 virtual void saveTextPos(GfxState *state);
230 virtual void restoreTextPos(GfxState *state);
232 //----- path painting
233 virtual void stroke(GfxState *state);
234 virtual void fill(GfxState *state);
235 virtual void eoFill(GfxState *state);
236 virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
237 double *pmat, int paintType, int tilingType, Dict *resDict,
238 double *mat, double *bbox,
239 int x0, int y0, int x1, int y1,
240 double xStep, double yStep);
241 virtual GBool functionShadedFill(GfxState *state,
242 GfxFunctionShading *shading);
243 virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double /*tMin*/, double /*tMax*/);
244 virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading, double /*sMin*/, double /*sMax*/);
246 //----- path clipping
247 virtual void clip(GfxState *state);
248 virtual void eoClip(GfxState *state);
249 virtual void clipToStrokePath(GfxState *state);
251 //----- text drawing
252 virtual void drawString(GfxState *state, GooString *s);
253 virtual void beginTextObject(GfxState *state);
254 virtual void endTextObject(GfxState *state);
256 //----- image drawing
257 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
258 int width, int height, GBool invert,
259 GBool interpolate, GBool inlineImg);
260 virtual void setSoftMaskFromImageMask(GfxState *state,
261 Object *ref, Stream *str,
262 int width, int height, GBool invert,
263 GBool inlineImg, double *baseMatrix);
264 virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
265 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
266 int width, int height, GfxImageColorMap *colorMap,
267 GBool interpolate, int *maskColors, GBool inlineImg);
268 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
269 int width, int height,
270 GfxImageColorMap *colorMap,
271 GBool interpolate,
272 Stream *maskStr, int maskWidth, int maskHeight,
273 GBool maskInvert, GBool maskInterpolate);
275 #if OPI_SUPPORT
276 //----- OPI functions
277 virtual void opiBegin(GfxState *state, Dict *opiDict);
278 virtual void opiEnd(GfxState *state, Dict *opiDict);
279 #endif
281 //----- Type 3 font operators
282 virtual void type3D0(GfxState *state, double wx, double wy);
283 virtual void type3D1(GfxState *state, double wx, double wy,
284 double llx, double lly, double urx, double ury);
286 //----- form XObjects
287 virtual void drawForm(Ref ref);
289 //----- PostScript XObjects
290 virtual void psXObject(Stream *psStream, Stream *level1Stream);
292 //----- miscellaneous
293 void setOffset(double x, double y)
294 { tx0 = x; ty0 = y; }
295 void setScale(double x, double y)
296 { xScale0 = x; yScale0 = y; }
297 void setRotate(int rotateA)
298 { rotate0 = rotateA; }
299 void setClip(double llx, double lly, double urx, double ury)
300 { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
301 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
302 void *data)
303 { underlayCbk = cbk; underlayCbkData = data; }
304 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
305 void *data)
306 { overlayCbk = cbk; overlayCbkData = data; }
307 void setDisplayText(GBool display) { displayText = display; }
309 private:
311 void init(PSOutputFunc outputFuncA, void *outputStreamA,
312 PSFileType fileTypeA, char *pstitle, PDFDoc *doc,
313 int firstPage, int lastPage, PSOutMode modeA,
314 int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
315 GBool manualCtrlA, int paperWidthA, int paperHeightA,
316 GBool noCropA, GBool duplexA);
317 void setupResources(Dict *resDict);
318 void setupFonts(Dict *resDict);
319 void setupFont(GfxFont *font, Dict *parentResDict);
320 void setupEmbeddedType1Font(Ref *id, GooString *psName);
321 void setupExternalType1Font(GooString *fileName, GooString *psName);
322 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName);
323 void setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName);
324 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName);
325 void setupExternalTrueTypeFont(GfxFont *font, GooString *fileName,
326 GooString *psName);
327 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName);
328 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName,
329 GBool needVerticalMetrics);
330 void setupExternalCIDTrueTypeFont(GfxFont *font,
331 GooString *fileName,
332 GooString *psName,
333 GBool needVerticalMetrics);
334 void setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString *psName);
335 void setupType3Font(GfxFont *font, GooString *psName, Dict *parentResDict);
336 GooString *makePSFontName(GfxFont *font, Ref *id);
337 void setupImages(Dict *resDict);
338 void setupImage(Ref id, Stream *str, GBool mask);
339 void setupForms(Dict *resDict);
340 void setupForm(Ref id, Object *strObj);
341 void addProcessColor(double c, double m, double y, double k);
342 void addCustomColor(GfxSeparationColorSpace *sepCS);
343 void doPath(GfxPath *path);
344 void maskToClippingPath(Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert);
345 void doImageL1(Object *ref, GfxImageColorMap *colorMap,
346 GBool invert, GBool inlineImg,
347 Stream *str, int width, int height, int len,
348 int *maskColors, Stream *maskStr,
349 int maskWidth, int maskHeight, GBool maskInvert);
350 void doImageL1Sep(Object *ref, GfxImageColorMap *colorMap,
351 GBool invert, GBool inlineImg,
352 Stream *str, int width, int height, int len,
353 int *maskColors, Stream *maskStr,
354 int maskWidth, int maskHeight, GBool maskInvert);
355 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
356 GBool invert, GBool inlineImg,
357 Stream *str, int width, int height, int len,
358 int *maskColors, Stream *maskStr,
359 int maskWidth, int maskHeight, GBool maskInvert);
360 void doImageL3(Object *ref, GfxImageColorMap *colorMap,
361 GBool invert, GBool inlineImg,
362 Stream *str, int width, int height, int len,
363 int *maskColors, Stream *maskStr,
364 int maskWidth, int maskHeight, GBool maskInvert);
365 void dumpColorSpaceL2(GfxColorSpace *colorSpace,
366 GBool genXform, GBool updateColors,
367 GBool map01);
368 GBool tilingPatternFillL1(GfxState *state, Catalog *cat, Object *str,
369 double *pmat, int paintType, int tilingType, Dict *resDict,
370 double *mat, double *bbox,
371 int x0, int y0, int x1, int y1,
372 double xStep, double yStep);
373 GBool tilingPatternFillL2(GfxState *state, Catalog *cat, Object *str,
374 double *pmat, int paintType, int tilingType, Dict *resDict,
375 double *mat, double *bbox,
376 int x0, int y0, int x1, int y1,
377 double xStep, double yStep);
379 #if OPI_SUPPORT
380 void opiBegin20(GfxState *state, Dict *dict);
381 void opiBegin13(GfxState *state, Dict *dict);
382 void opiTransform(GfxState *state, double x0, double y0,
383 double *x1, double *y1);
384 #endif
385 void cvtFunction(Function *func, GBool invertPSFunction = gFalse);
386 GooString *filterPSName(GooString *name);
388 // Write the document-level setup.
389 void writeDocSetup(PDFDoc *doc, Catalog *catalog, int firstPage, int lastPage, GBool duplexA);
391 void writePSChar(char c);
392 void writePS(const char *s);
393 void writePSBuf(const char *s, int len);
394 void writePSFmt(const char *fmt, ...);
395 void writePSString(GooString *s);
396 void writePSName(const char *s);
397 GooString *filterPSLabel(GooString *label, GBool *needParens=0);
398 void writePSTextLine(GooString *s);
400 PSLevel level; // PostScript level (1, 2, separation)
401 PSOutMode mode; // PostScript mode (PS, EPS, form)
402 int paperWidth; // width of paper, in pts
403 int paperHeight; // height of paper, in pts
404 GBool paperMatch; // true if paper size is set to match each page
405 int prevWidth; // width of previous page
406 // (only psModePSOrigPageSizes output mode)
407 int prevHeight; // height of previous page
408 // (only psModePSOrigPageSizes output mode)
409 int imgLLX, imgLLY, // imageable area, in pts
410 imgURX, imgURY;
411 GBool preload; // load all images into memory, and
412 // predefine forms
413 GBool noCrop;
415 PSOutputFunc outputFunc;
416 void *outputStream;
417 PSFileType fileType; // file / pipe / stdout
418 GBool manualCtrl;
419 int seqPage; // current sequential page number
420 void (*underlayCbk)(PSOutputDev *psOut, void *data);
421 void *underlayCbkData;
422 void (*overlayCbk)(PSOutputDev *psOut, void *data);
423 void *overlayCbkData;
424 GooString *(*customCodeCbk)(PSOutputDev *psOut,
425 PSOutCustomCodeLocation loc, int n,
426 void *data);
427 void *customCodeCbkData;
429 PDFDoc *doc;
430 XRef *xref; // the xref table for this PDF file
432 Ref *fontIDs; // list of object IDs of all used fonts
433 int fontIDLen; // number of entries in fontIDs array
434 int fontIDSize; // size of fontIDs array
435 std::set<int> resourceIDs; // list of object IDs of objects containing Resources we've already set up
436 GooHash *fontNames; // all used font names
437 PST1FontName *t1FontNames; // font names for Type 1/1C fonts
438 int t1FontNameLen; // number of entries in t1FontNames array
439 int t1FontNameSize; // size of t1FontNames array
440 PSFont8Info *font8Info; // info for 8-bit fonts
441 int font8InfoLen; // number of entries in font8Info array
442 int font8InfoSize; // size of font8Info array
443 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
444 int font16EncLen; // number of entries in font16Enc array
445 int font16EncSize; // size of font16Enc array
446 Ref *imgIDs; // list of image IDs for in-memory images
447 int imgIDLen; // number of entries in imgIDs array
448 int imgIDSize; // size of imgIDs array
449 Ref *formIDs; // list of IDs for predefined forms
450 int formIDLen; // number of entries in formIDs array
451 int formIDSize; // size of formIDs array
452 int numSaves; // current number of gsaves
453 int numTilingPatterns; // current number of nested tiling patterns
454 int nextFunc; // next unique number to use for a function
456 GooList *paperSizes; // list of used paper sizes, if paperMatch
457 // is true [PSOutPaperSize]
458 std::map<int,int> pagePaperSize; // page num to paperSize entry mapping
459 double tx0, ty0; // global translation
460 double xScale0, yScale0; // global scaling
461 int rotate0; // rotation angle (0, 90, 180, 270)
462 double clipLLX0, clipLLY0,
463 clipURX0, clipURY0;
464 double tx, ty; // global translation for current page
465 double xScale, yScale; // global scaling for current page
466 int rotate; // rotation angle for current page
467 double epsX1, epsY1, // EPS bounding box (unrotated)
468 epsX2, epsY2;
470 GooString *embFontList; // resource comments for embedded fonts
472 int processColors; // used process colors
473 PSOutCustomColor // used custom colors
474 *customColors;
476 GBool haveTextClip; // set if text has been drawn with a
477 // clipping render mode
479 GBool inType3Char; // inside a Type 3 CharProc
480 GBool inUncoloredPattern; // inside a uncolored pattern (PaintType = 2)
481 GooString *t3String; // Type 3 content string
482 double t3WX, t3WY, // Type 3 character parameters
483 t3LLX, t3LLY, t3URX, t3URY;
484 GBool t3FillColorOnly; // operators should only use the fill color
485 GBool t3Cacheable; // cleared if char is not cacheable
486 GBool t3NeedsRestore; // set if a 'q' operator was issued
487 GBool forceRasterize; // forces the page to be rasterized into a image before printing
488 GBool displayText; // displayText
490 #if OPI_SUPPORT
491 int opi13Nest; // nesting level of OPI 1.3 objects
492 int opi20Nest; // nesting level of OPI 2.0 objects
493 #endif
495 GBool ok; // set up ok?
497 friend class WinPDFPrinter;
500 #endif