"Fossies" - the Fresh Open Source Software Archive 
Member "xpdf-4.04/xpdf/PSOutputDev.h" (18 Apr 2022, 19106 Bytes) of package /linux/misc/xpdf-4.04.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 //========================================================================
2 //
3 // PSOutputDev.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef PSOUTPUTDEV_H
10 #define PSOUTPUTDEV_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include <stddef.h>
19 #include "config.h"
20 #include "Object.h"
21 #include "GlobalParams.h"
22 #include "OutputDev.h"
23
24 class GHash;
25 class PDFDoc;
26 class XRef;
27 class Function;
28 class GfxPath;
29 class GfxFont;
30 class GfxColorSpace;
31 class GfxDeviceGrayColorSpace;
32 class GfxCalGrayColorSpace;
33 class GfxDeviceRGBColorSpace;
34 class GfxCalRGBColorSpace;
35 class GfxDeviceCMYKColorSpace;
36 class GfxLabColorSpace;
37 class GfxICCBasedColorSpace;
38 class GfxIndexedColorSpace;
39 class GfxSeparationColorSpace;
40 class GfxDeviceNColorSpace;
41 class GfxFunctionShading;
42 class GfxAxialShading;
43 class GfxRadialShading;
44 class PDFRectangle;
45 class PSOutCustomColor;
46 class PSOutputDev;
47 class PSFontFileInfo;
48
49 //------------------------------------------------------------------------
50 // PSOutputDev
51 //------------------------------------------------------------------------
52
53 enum PSOutMode {
54 psModePS,
55 psModeEPS,
56 psModeForm
57 };
58
59 enum PSFileType {
60 psFile, // write to file
61 psPipe, // write to pipe
62 psStdout, // write to stdout
63 psGeneric // write to a generic stream
64 };
65
66 enum PSOutCustomCodeLocation {
67 psOutCustomDocSetup,
68 psOutCustomPageSetup
69 };
70
71 typedef void (*PSOutputFunc)(void *stream, const char *data, int len);
72
73 typedef GString *(*PSOutCustomCodeCbk)(PSOutputDev *psOut,
74 PSOutCustomCodeLocation loc, int n,
75 void *data);
76
77 class PSOutputDev: public OutputDev {
78 public:
79
80 // Open a PostScript output file, and write the prolog.
81 PSOutputDev(char *fileName, PDFDoc *docA,
82 int firstPageA, int lastPageA, PSOutMode modeA,
83 int imgLLXA = 0, int imgLLYA = 0,
84 int imgURXA = 0, int imgURYA = 0,
85 GBool manualCtrlA = gFalse,
86 PSOutCustomCodeCbk customCodeCbkA = NULL,
87 void *customCodeCbkDataA = NULL,
88 GBool honorUserUnitA = gFalse,
89 GBool fileNameIsUTF8 = gFalse);
90
91 // Open a PSOutputDev that will write to a generic stream.
92 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
93 PDFDoc *docA,
94 int firstPageA, int lastPageA, PSOutMode modeA,
95 int imgLLXA = 0, int imgLLYA = 0,
96 int imgURXA = 0, int imgURYA = 0,
97 GBool manualCtrlA = gFalse,
98 PSOutCustomCodeCbk customCodeCbkA = NULL,
99 void *customCodeCbkDataA = NULL,
100 GBool honorUserUnitA = gFalse);
101
102 // Destructor -- writes the trailer and closes the file.
103 virtual ~PSOutputDev();
104
105 // Check if file was successfully created.
106 virtual GBool isOk() { return ok; }
107
108 // Returns false if there have been any errors on the output stream.
109 GBool checkIO();
110
111 //---- get info about output device
112
113 // Does this device use upside-down coordinates?
114 // (Upside-down means (0,0) is the top left corner of the page.)
115 virtual GBool upsideDown() { return gFalse; }
116
117 // Does this device use drawChar() or drawString()?
118 virtual GBool useDrawChar() { return gFalse; }
119
120 // Does this device use tilingPatternFill()? If this returns false,
121 // tiling pattern fills will be reduced to a series of other drawing
122 // operations.
123 virtual GBool useTilingPatternFill() { return gTrue; }
124
125 // Does this device use drawForm()? If this returns false,
126 // form-type XObjects will be interpreted (i.e., unrolled).
127 virtual GBool useDrawForm() { return preload; }
128
129 // Does this device use beginType3Char/endType3Char? Otherwise,
130 // text in Type 3 fonts will be drawn with drawChar/drawString.
131 virtual GBool interpretType3Chars() { return gFalse; }
132
133 //----- header/trailer (used only if manualCtrl is true)
134
135 // Write the document-level header.
136 void writeHeader(PDFRectangle *mediaBox, PDFRectangle *cropBox,
137 int pageRotate);
138
139 // Write the Xpdf procset.
140 void writeXpdfProcset();
141
142 // Write the document-level setup.
143 void writeDocSetup(Catalog *catalog);
144
145 // Write the trailer for the current page.
146 void writePageTrailer();
147
148 // Write the document trailer.
149 void writeTrailer();
150
151 //----- initialization and control
152
153 // Check to see if a page slice should be displayed. If this
154 // returns false, the page display is aborted. Typically, an
155 // OutputDev will use some alternate means to display the page
156 // before returning false.
157 virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
158 int rotate, GBool useMediaBox, GBool crop,
159 int sliceX, int sliceY, int sliceW, int sliceH,
160 GBool printing,
161 GBool (*abortCheckCbk)(void *data) = NULL,
162 void *abortCheckCbkData = NULL);
163
164 // Start a page.
165 virtual void startPage(int pageNum, GfxState *state);
166
167 // End a page.
168 virtual void endPage();
169
170 //----- save/restore graphics state
171 virtual void saveState(GfxState *state);
172 virtual void restoreState(GfxState *state);
173
174 //----- update graphics state
175 virtual void updateCTM(GfxState *state, double m11, double m12,
176 double m21, double m22, double m31, double m32);
177 virtual void updateLineDash(GfxState *state);
178 virtual void updateFlatness(GfxState *state);
179 virtual void updateLineJoin(GfxState *state);
180 virtual void updateLineCap(GfxState *state);
181 virtual void updateMiterLimit(GfxState *state);
182 virtual void updateLineWidth(GfxState *state);
183 virtual void updateFillColorSpace(GfxState *state);
184 virtual void updateStrokeColorSpace(GfxState *state);
185 virtual void updateFillColor(GfxState *state);
186 virtual void updateStrokeColor(GfxState *state);
187 virtual void updateFillOverprint(GfxState *state);
188 virtual void updateStrokeOverprint(GfxState *state);
189 virtual void updateOverprintMode(GfxState *state);
190 virtual void updateTransfer(GfxState *state);
191
192 //----- update text state
193 virtual void updateFont(GfxState *state);
194 virtual void updateTextMat(GfxState *state);
195 virtual void updateCharSpace(GfxState *state);
196 virtual void updateRender(GfxState *state);
197 virtual void updateRise(GfxState *state);
198 virtual void updateWordSpace(GfxState *state);
199 virtual void updateHorizScaling(GfxState *state);
200 virtual void updateTextPos(GfxState *state);
201 virtual void updateTextShift(GfxState *state, double shift);
202 virtual void saveTextPos(GfxState *state);
203 virtual void restoreTextPos(GfxState *state);
204
205 //----- path painting
206 virtual void stroke(GfxState *state);
207 virtual void fill(GfxState *state);
208 virtual void eoFill(GfxState *state);
209 virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *strRef,
210 int paintType, int tilingType, Dict *resDict,
211 double *mat, double *bbox,
212 int x0, int y0, int x1, int y1,
213 double xStep, double yStep);
214 virtual GBool shadedFill(GfxState *state, GfxShading *shading);
215
216 //----- path clipping
217 virtual void clip(GfxState *state);
218 virtual void eoClip(GfxState *state);
219 virtual void clipToStrokePath(GfxState *state);
220
221 //----- text drawing
222 virtual void drawString(GfxState *state, GString *s);
223 virtual void endTextObject(GfxState *state);
224
225 //----- image drawing
226 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
227 int width, int height, GBool invert,
228 GBool inlineImg, GBool interpolate);
229 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
230 int width, int height, GfxImageColorMap *colorMap,
231 int *maskColors, GBool inlineImg, GBool interpolate);
232 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
233 int width, int height,
234 GfxImageColorMap *colorMap,
235 Object *maskRef, Stream *maskStr,
236 int maskWidth, int maskHeight,
237 GBool maskInvert, GBool interpolate);
238
239 #if OPI_SUPPORT
240 //----- OPI functions
241 virtual void opiBegin(GfxState *state, Dict *opiDict);
242 virtual void opiEnd(GfxState *state, Dict *opiDict);
243 #endif
244
245 //----- Type 3 font operators
246 virtual void type3D0(GfxState *state, double wx, double wy);
247 virtual void type3D1(GfxState *state, double wx, double wy,
248 double llx, double lly, double urx, double ury);
249
250 //----- form XObjects
251 virtual void drawForm(Ref ref);
252
253 //----- PostScript XObjects
254 virtual void psXObject(Stream *psStream, Stream *level1Stream);
255
256 //----- miscellaneous
257 void setImageableArea(int imgLLXA, int imgLLYA, int imgURXA, int imgURYA)
258 { imgLLX = imgLLXA; imgLLY = imgLLYA; imgURX = imgURXA; imgURY = imgURYA; }
259 void setOffset(double x, double y)
260 { tx0 = x; ty0 = y; }
261 void setScale(double x, double y)
262 { xScale0 = x; yScale0 = y; }
263 void setRotate(int rotateA)
264 { rotate0 = rotateA; }
265 void setClip(double llx, double lly, double urx, double ury)
266 { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
267 void setExpandSmallPages(GBool expand)
268 { expandSmallPages = expand; }
269 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
270 void *data)
271 { underlayCbk = cbk; underlayCbkData = data; }
272 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
273 void *data)
274 { overlayCbk = cbk; overlayCbkData = data; }
275
276 void writePSChar(char c);
277 void writePSBlock(char *s, int len);
278 void writePS(const char *s);
279 void writePSFmt(const char *fmt, ...);
280 void writePSString(GString *s);
281 void writePSName(const char *s);
282
283 private:
284
285 void init(PSOutputFunc outputFuncA, void *outputStreamA,
286 PSFileType fileTypeA, PDFDoc *docA,
287 int firstPageA, int lastPageA, PSOutMode modeA,
288 int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
289 GBool manualCtrlA, GBool honorUserUnitA);
290 GBool checkIfPageNeedsToBeRasterized(int pg);
291 void setupResources(Dict *resDict);
292 void setupFonts(Dict *resDict);
293 void setupFont(GfxFont *font, Dict *parentResDict);
294 PSFontFileInfo *setupEmbeddedType1Font(GfxFont *font, Ref *id);
295 PSFontFileInfo *setupExternalType1Font(GfxFont *font, GString *fileName);
296 PSFontFileInfo *setupEmbeddedType1CFont(GfxFont *font, Ref *id);
297 PSFontFileInfo *setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id);
298 PSFontFileInfo *setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id);
299 PSFontFileInfo *setupExternalTrueTypeFont(GfxFont *font, GString *fileName,
300 int fontNum);
301 PSFontFileInfo *setupEmbeddedCIDType0Font(GfxFont *font, Ref *id);
302 PSFontFileInfo *setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id,
303 GBool needVerticalMetrics);
304 PSFontFileInfo *setupExternalCIDTrueTypeFont(GfxFont *font,
305 GString *fileName,
306 int fontNum,
307 GBool needVerticalMetrics);
308 PSFontFileInfo *setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id);
309 PSFontFileInfo *setupExternalOpenTypeCFFFont(GfxFont *font,
310 GString *fileName);
311 PSFontFileInfo *setupType3Font(GfxFont *font, Dict *parentResDict);
312 GString *makePSFontName(GfxFont *font, Ref *id);
313 GString *fixType1Font(GString *font, int length1, int length2);
314 GBool splitType1PFA(Guchar *font, int fontSize,
315 int length1, int length2,
316 GString *textSection, GString *binSection);
317 GBool splitType1PFB(Guchar *font, int fontSize,
318 GString *textSection, GString *binSection);
319 GString *asciiHexDecodeType1EexecSection(GString *in);
320 GBool fixType1EexecSection(GString *binSection, GString *out);
321 GString *copyType1PFA(Guchar *font, int fontSize);
322 GString *copyType1PFB(Guchar *font, int fontSize);
323 void renameType1Font(GString *font, GString *name);
324 void setupDefaultFont();
325 void setupImages(Dict *resDict);
326 void setupImage(Ref id, Stream *str, GBool mask, Array *colorKeyMask);
327 void setupForms(Dict *resDict);
328 void setupForm(Object *strRef, Object *strObj);
329 void addProcessColor(double c, double m, double y, double k);
330 void addCustomColor(GfxState *state, GfxSeparationColorSpace *sepCS);
331 void addCustomColors(GfxState *state, GfxDeviceNColorSpace *devnCS);
332 void tilingPatternFillL1(GfxState *state, Gfx *gfx, Object *strRef,
333 int paintType, int tilingType, Dict *resDict,
334 double *mat, double *bbox,
335 int x0, int y0, int x1, int y1,
336 double xStep, double yStep);
337 void tilingPatternFillL2(GfxState *state, Gfx *gfx, Object *strRef,
338 int paintType, int tilingType, Dict *resDict,
339 double *mat, double *bbox,
340 int x0, int y0, int x1, int y1,
341 double xStep, double yStep);
342 GBool functionShadedFill(GfxState *state,
343 GfxFunctionShading *shading);
344 GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
345 GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
346 void doPath(GfxPath *path);
347 void doImageL1(Object *ref, GfxState *state,
348 GfxImageColorMap *colorMap,
349 GBool invert, GBool inlineImg,
350 Stream *str, int width, int height, int len);
351 void doImageL1Sep(GfxState *state, GfxImageColorMap *colorMap,
352 GBool invert, GBool inlineImg,
353 Stream *str, int width, int height, int len);
354 void doImageL2(Object *ref, GfxState *state,
355 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 convertColorKeyMaskToClipRects(GfxImageColorMap *colorMap,
361 Stream *str,
362 int width, int height,
363 int *maskColors);
364 void convertExplicitMaskToClipRects(Stream *maskStr,
365 int maskWidth, int maskHeight,
366 GBool maskInvert);
367 void doImageL3(Object *ref, GfxState *state,
368 GfxImageColorMap *colorMap,
369 GBool invert, GBool inlineImg,
370 Stream *str, int width, int height, int len,
371 int *maskColors, Stream *maskStr,
372 int maskWidth, int maskHeight, GBool maskInvert);
373 void dumpColorSpaceL2(GfxState *state, GfxColorSpace *colorSpace,
374 GBool genXform, GBool updateColors,
375 GBool map01);
376 void dumpDeviceGrayColorSpace(GfxDeviceGrayColorSpace *cs,
377 GBool genXform, GBool updateColors,
378 GBool map01);
379 void dumpCalGrayColorSpace(GfxCalGrayColorSpace *cs,
380 GBool genXform, GBool updateColors,
381 GBool map01);
382 void dumpDeviceRGBColorSpace(GfxDeviceRGBColorSpace *cs,
383 GBool genXform, GBool updateColors,
384 GBool map01);
385 void dumpCalRGBColorSpace(GfxCalRGBColorSpace *cs,
386 GBool genXform, GBool updateColors,
387 GBool map01);
388 void dumpDeviceCMYKColorSpace(GfxDeviceCMYKColorSpace *cs,
389 GBool genXform, GBool updateColors,
390 GBool map01);
391 void dumpLabColorSpace(GfxLabColorSpace *cs,
392 GBool genXform, GBool updateColors,
393 GBool map01);
394 void dumpICCBasedColorSpace(GfxState *state, GfxICCBasedColorSpace *cs,
395 GBool genXform, GBool updateColors,
396 GBool map01);
397 void dumpIndexedColorSpace(GfxState *state,
398 GfxIndexedColorSpace *cs,
399 GBool genXform, GBool updateColors,
400 GBool map01);
401 void dumpSeparationColorSpace(GfxState *state,
402 GfxSeparationColorSpace *cs,
403 GBool genXform, GBool updateColors,
404 GBool map01);
405 void dumpDeviceNColorSpaceL2(GfxState *state, GfxDeviceNColorSpace *cs,
406 GBool genXform, GBool updateColors,
407 GBool map01);
408 void dumpDeviceNColorSpaceL3(GfxState *state, GfxDeviceNColorSpace *cs,
409 GBool genXform, GBool updateColors,
410 GBool map01);
411 GString *createDeviceNTintFunc(GfxDeviceNColorSpace *cs);
412 #if OPI_SUPPORT
413 void opiBegin20(GfxState *state, Dict *dict);
414 void opiBegin13(GfxState *state, Dict *dict);
415 void opiTransform(GfxState *state, double x0, double y0,
416 double *x1, double *y1);
417 GBool getFileSpec(Object *fileSpec, Object *fileName);
418 #endif
419 void cvtFunction(Function *func);
420 GString *filterPSName(GString *name);
421 void writePSTextLine(GString *s);
422
423 PSLevel level; // PostScript level
424 PSOutMode mode; // PostScript mode (PS, EPS, form)
425 int paperWidth; // width of paper, in pts
426 int paperHeight; // height of paper, in pts
427 GBool paperMatch; // true if paper size is set to match each page
428 int imgLLX, imgLLY, // imageable area, in pts
429 imgURX, imgURY;
430 GBool preload; // load all images into memory, and
431 // predefine forms
432
433 PSOutputFunc outputFunc;
434 void *outputStream;
435 PSFileType fileType; // file / pipe / stdout
436 GBool manualCtrl;
437 int seqPage; // current sequential page number
438 void (*underlayCbk)(PSOutputDev *psOut, void *data);
439 void *underlayCbkData;
440 void (*overlayCbk)(PSOutputDev *psOut, void *data);
441 void *overlayCbkData;
442 GString *(*customCodeCbk)(PSOutputDev *psOut,
443 PSOutCustomCodeLocation loc, int n,
444 void *data);
445 void *customCodeCbkData;
446 GBool honorUserUnit;
447
448 PDFDoc *doc;
449 XRef *xref; // the xref table for this PDF file
450
451 int firstPage; // first output page
452 int lastPage; // last output page
453 char *rasterizePage; // boolean for each page - true if page
454 // needs to be rasterized
455
456 GList *fontInfo; // info for each font [PSFontInfo]
457 GHash *fontFileInfo; // info for each font file [PSFontFileInfo]
458 Ref *imgIDs; // list of image IDs for in-memory images
459 int imgIDLen; // number of entries in imgIDs array
460 int imgIDSize; // size of imgIDs array
461 Ref *formIDs; // list of IDs for predefined forms
462 int formIDLen; // number of entries in formIDs array
463 int formIDSize; // size of formIDs array
464 char *visitedResources; // vector of resource objects already visited
465 GBool noStateChanges; // true if there have been no state changes
466 // since the last save
467 GList *saveStack; // "no state changes" flag for each
468 // pending save
469 int numTilingPatterns; // current number of nested tiling patterns
470 int nextFunc; // next unique number to use for a function
471
472 GList *paperSizes; // list of used paper sizes, if paperMatch
473 // is true [PSOutPaperSize]
474 double tx0, ty0; // global translation
475 double xScale0, yScale0; // global scaling
476 int rotate0; // rotation angle (0, 90, 180, 270)
477 double clipLLX0, clipLLY0,
478 clipURX0, clipURY0;
479 GBool expandSmallPages; // expand smaller pages to fill paper
480 double tx, ty; // global translation for current page
481 double xScale, yScale; // global scaling for current page
482 int rotate; // rotation angle for current page
483 double epsX1, epsY1, // EPS bounding box (unrotated)
484 epsX2, epsY2;
485
486 GString *embFontList; // resource comments for embedded fonts
487
488 int processColors; // used process colors
489 PSOutCustomColor // used custom colors
490 *customColors;
491
492 GBool haveTextClip; // set if text has been drawn with a
493 // clipping render mode
494
495 GBool inType3Char; // inside a Type 3 CharProc
496 GString *t3String; // Type 3 content string
497 double t3WX, t3WY, // Type 3 character parameters
498 t3LLX, t3LLY, t3URX, t3URY;
499 GBool t3FillColorOnly; // operators should only use the fill color
500 GBool t3Cacheable; // cleared if char is not cacheable
501 GBool t3NeedsRestore; // set if a 'q' operator was issued
502
503 #if OPI_SUPPORT
504 int opi13Nest; // nesting level of OPI 1.3 objects
505 int opi20Nest; // nesting level of OPI 2.0 objects
506 #endif
507
508 GBool ok; // set up ok?
509
510 friend class WinPDFPrinter;
511 };
512
513 #endif