]> git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/PSOutputDev.h
Merge changes from CUPS 1.4svn-r7199.
[thirdparty/cups.git] / pdftops / PSOutputDev.h
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 <config.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 Function;
25 class GfxPath;
26 class GfxFont;
27 class GfxColorSpace;
28 class GfxSeparationColorSpace;
29 class PDFRectangle;
30 struct PSFont16Enc;
31 class PSOutCustomColor;
32
33 //------------------------------------------------------------------------
34 // PSOutputDev
35 //------------------------------------------------------------------------
36
37 enum PSOutMode {
38 psModePS,
39 psModeEPS,
40 psModeForm
41 };
42
43 enum PSFileType {
44 psFile, // write to file
45 psPipe, // write to pipe
46 psStdout, // write to stdout
47 psGeneric // write to a generic stream
48 };
49
50 typedef void (*PSOutputFunc)(void *stream, char *data, int len);
51
52 class PSOutputDev: public OutputDev {
53 public:
54
55 // Open a PostScript output file, and write the prolog.
56 PSOutputDev(char *fileName, XRef *xrefA, Catalog *catalog,
57 int firstPage, int lastPage, PSOutMode modeA,
58 int imgLLXA = 0, int imgLLYA = 0,
59 int imgURXA = 0, int imgURYA = 0,
60 GBool manualCtrlA = gFalse,
61 const char *pageRangesA = (const char *)0);
62
63 // Open a PSOutputDev that will write to a generic stream.
64 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
65 XRef *xrefA, Catalog *catalog,
66 int firstPage, int lastPage, PSOutMode modeA,
67 int imgLLXA = 0, int imgLLYA = 0,
68 int imgURXA = 0, int imgURYA = 0,
69 GBool manualCtrlA = gFalse,
70 const char *pageRangesA = (const char *)0);
71
72 // Destructor -- writes the trailer and closes the file.
73 virtual ~PSOutputDev();
74
75 // Check if file was successfully created.
76 virtual GBool isOk() { return ok; }
77
78 //---- get info about output device
79
80 // Does this device use upside-down coordinates?
81 // (Upside-down means (0,0) is the top left corner of the page.)
82 virtual GBool upsideDown() { return gFalse; }
83
84 // Does this device use drawChar() or drawString()?
85 virtual GBool useDrawChar() { return gFalse; }
86
87 // Does this device use tilingPatternFill()? If this returns false,
88 // tiling pattern fills will be reduced to a series of other drawing
89 // operations.
90 virtual GBool useTilingPatternFill() { return gTrue; }
91
92 // Does this device use functionShadedFill(), axialShadedFill(), and
93 // radialShadedFill()? If this returns false, these shaded fills
94 // will be reduced to a series of other drawing operations.
95 virtual GBool useShadedFills()
96 { return level == psLevel2 || level == psLevel3; }
97
98 // Does this device use beginType3Char/endType3Char? Otherwise,
99 // text in Type 3 fonts will be drawn with drawChar/drawString.
100 virtual GBool interpretType3Chars() { return gFalse; }
101
102 //----- header/trailer (used only if manualCtrl is true)
103
104 // Write the document-level header.
105 void writeHeader(int firstPage, int lastPage,
106 PDFRectangle *mediaBox, PDFRectangle *cropBox,
107 int pageRotate);
108
109 // Write the Xpdf procset.
110 void writeXpdfProcset();
111
112 // Write the document-level setup.
113 void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
114
115 // Write the trailer for the current page.
116 void writePageTrailer();
117
118 // Write the document trailer.
119 void writeTrailer();
120
121 //----- initialization and control
122
123 // Start a page.
124 virtual GBool startPage(int pageNum, GfxState *state);
125
126 // End a page.
127 virtual void endPage();
128
129 //----- save/restore graphics state
130 virtual void saveState(GfxState *state);
131 virtual void restoreState(GfxState *state);
132
133 //----- update graphics state
134 virtual void updateCTM(GfxState *state, double m11, double m12,
135 double m21, double m22, double m31, double m32);
136 virtual void updateLineDash(GfxState *state);
137 virtual void updateFlatness(GfxState *state);
138 virtual void updateLineJoin(GfxState *state);
139 virtual void updateLineCap(GfxState *state);
140 virtual void updateMiterLimit(GfxState *state);
141 virtual void updateLineWidth(GfxState *state);
142 virtual void updateFillColorSpace(GfxState *state);
143 virtual void updateStrokeColorSpace(GfxState *state);
144 virtual void updateFillColor(GfxState *state);
145 virtual void updateStrokeColor(GfxState *state);
146 virtual void updateFillOverprint(GfxState *state);
147 virtual void updateStrokeOverprint(GfxState *state);
148
149 //----- update text state
150 virtual void updateFont(GfxState *state);
151 virtual void updateTextMat(GfxState *state);
152 virtual void updateCharSpace(GfxState *state);
153 virtual void updateRender(GfxState *state);
154 virtual void updateRise(GfxState *state);
155 virtual void updateWordSpace(GfxState *state);
156 virtual void updateHorizScaling(GfxState *state);
157 virtual void updateTextPos(GfxState *state);
158 virtual void updateTextShift(GfxState *state, double shift);
159
160 //----- path painting
161 virtual void stroke(GfxState *state);
162 virtual void fill(GfxState *state);
163 virtual void eoFill(GfxState *state);
164 virtual void tilingPatternFill(GfxState *state, Object *str,
165 int paintType, Dict *resDict,
166 double *mat, double *bbox,
167 int x0, int y0, int x1, int y1,
168 double xStep, double yStep);
169 virtual void functionShadedFill(GfxState *state,
170 GfxFunctionShading *shading);
171 virtual void axialShadedFill(GfxState *state, GfxAxialShading *shading);
172 virtual void radialShadedFill(GfxState *state, GfxRadialShading *shading);
173
174 //----- path clipping
175 virtual void clip(GfxState *state);
176 virtual void eoClip(GfxState *state);
177
178 //----- text drawing
179 virtual void drawString(GfxState *state, GString *s);
180 virtual void endTextObject(GfxState *state);
181
182 //----- image drawing
183 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
184 int width, int height, GBool invert,
185 GBool inlineImg);
186 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
187 int width, int height, GfxImageColorMap *colorMap,
188 int *maskColors, GBool inlineImg);
189 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
190 int width, int height,
191 GfxImageColorMap *colorMap,
192 Stream *maskStr, int maskWidth, int maskHeight,
193 GBool maskInvert);
194
195 #if OPI_SUPPORT
196 //----- OPI functions
197 virtual void opiBegin(GfxState *state, Dict *opiDict);
198 virtual void opiEnd(GfxState *state, Dict *opiDict);
199 #endif
200
201 //----- Type 3 font operators
202 virtual void type3D0(GfxState *state, double wx, double wy);
203 virtual void type3D1(GfxState *state, double wx, double wy,
204 double llx, double lly, double urx, double ury);
205
206 //----- PostScript XObjects
207 virtual void psXObject(Stream *psStream, Stream *level1Stream);
208
209 //----- miscellaneous
210 void setOffset(double x, double y)
211 { tx0 = x; ty0 = y; }
212 void setScale(double x, double y)
213 { xScale0 = x; yScale0 = y; }
214 void setRotate(int rotateA)
215 { rotate0 = rotateA; }
216 void setClip(double llx, double lly, double urx, double ury)
217 { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
218 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
219 void *data)
220 { underlayCbk = cbk; underlayCbkData = data; }
221 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
222 void *data)
223 { overlayCbk = cbk; overlayCbkData = data; }
224
225 private:
226
227 void init(PSOutputFunc outputFuncA, void *outputStreamA,
228 PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
229 int firstPage, int lastPage, PSOutMode modeA,
230 int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
231 GBool manualCtrlA, const char *pageRangesA);
232 void setupResources(Dict *resDict);
233 void setupFonts(Dict *resDict);
234 void setupFont(GfxFont *font, Dict *parentResDict);
235 void setupEmbeddedType1Font(Ref *id, GString *psName);
236 void setupExternalType1Font(GString *fileName, GString *psName);
237 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
238 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
239 void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
240 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
241 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName,
242 GBool needVerticalMetrics);
243 void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
244 void setupImages(Dict *resDict);
245 void setupImage(Ref id, Stream *str);
246 void addProcessColor(double c, double m, double y, double k);
247 void addCustomColor(GfxSeparationColorSpace *sepCS);
248 void doPath(GfxPath *path);
249 void doImageL1(Object *ref, GfxImageColorMap *colorMap,
250 GBool invert, GBool inlineImg,
251 Stream *str, int width, int height, int len);
252 void doImageL1Sep(GfxImageColorMap *colorMap,
253 GBool invert, GBool inlineImg,
254 Stream *str, int width, int height, int len);
255 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
256 GBool invert, GBool inlineImg,
257 Stream *str, int width, int height, int len,
258 int *maskColors, Stream *maskStr,
259 int maskWidth, int maskHeight, GBool maskInvert);
260 void dumpColorSpaceL2(GfxColorSpace *colorSpace,
261 GBool genXform, GBool updateColors);
262 #if OPI_SUPPORT
263 void opiBegin20(GfxState *state, Dict *dict);
264 void opiBegin13(GfxState *state, Dict *dict);
265 void opiTransform(GfxState *state, double x0, double y0,
266 double *x1, double *y1);
267 GBool getFileSpec(Object *fileSpec, Object *fileName);
268 #endif
269 void cvtFunction(Function *func);
270 void writePSChar(char c);
271 void writePS(char *s);
272 void writePSFmt(const char *fmt, ...);
273 void writePSString(GString *s);
274 void writePSName(char *s);
275 GString *filterPSName(GString *name);
276 GBool checkRange(int page);
277
278 PSLevel level; // PostScript level (1, 2, separation)
279 PSOutMode mode; // PostScript mode (PS, EPS, form)
280 int paperWidth; // width of paper, in pts
281 int paperHeight; // height of paper, in pts
282 int imgLLX, imgLLY, // imageable area, in pts
283 imgURX, imgURY;
284
285 PSOutputFunc outputFunc;
286 void *outputStream;
287 PSFileType fileType; // file / pipe / stdout
288 GBool manualCtrl;
289 int seqPage; // current sequential page number
290 void (*underlayCbk)(PSOutputDev *psOut, void *data);
291 void *underlayCbkData;
292 void (*overlayCbk)(PSOutputDev *psOut, void *data);
293 void *overlayCbkData;
294
295 XRef *xref; // the xref table for this PDF file
296
297 Ref *fontIDs; // list of object IDs of all used fonts
298 int fontIDLen; // number of entries in fontIDs array
299 int fontIDSize; // size of fontIDs array
300 Ref *fontFileIDs; // list of object IDs of all embedded fonts
301 int fontFileIDLen; // number of entries in fontFileIDs array
302 int fontFileIDSize; // size of fontFileIDs array
303 GString **fontFileNames; // list of names of all embedded external fonts
304 int fontFileNameLen; // number of entries in fontFileNames array
305 int fontFileNameSize; // size of fontFileNames array
306 int nextTrueTypeNum; // next unique number to append to a TrueType
307 // font name
308 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
309 int font16EncLen; // number of entries in font16Enc array
310 int font16EncSize; // size of font16Enc array
311 GList *xobjStack; // stack of XObject dicts currently being
312 // processed
313 int numSaves; // current number of gsaves
314 int numTilingPatterns; // current number of nested tiling patterns
315 int nextFunc; // next unique number to use for a function
316
317 double tx0, ty0; // global translation
318 double xScale0, yScale0; // global scaling
319 int rotate0; // rotation angle (0, 90, 180, 270)
320 double clipLLX0, clipLLY0,
321 clipURX0, clipURY0;
322 double tx, ty; // global translation for current page
323 double xScale, yScale; // global scaling for current page
324 int rotate; // rotation angle for current page
325 double epsX1, epsY1, // EPS bounding box (unrotated)
326 epsX2, epsY2;
327
328 GString *embFontList; // resource comments for embedded fonts
329
330 int processColors; // used process colors
331 PSOutCustomColor // used custom colors
332 *customColors;
333
334 GBool haveTextClip; // set if text has been drawn with a
335 // clipping render mode
336
337 GBool inType3Char; // inside a Type 3 CharProc
338 GString *t3String; // Type 3 content string
339 double t3WX, t3WY, // Type 3 character parameters
340 t3LLX, t3LLY, t3URX, t3URY;
341 GBool t3Cacheable; // cleared if char is not cacheable
342
343 #if OPI_SUPPORT
344 int opi13Nest; // nesting level of OPI 1.3 objects
345 int opi20Nest; // nesting level of OPI 2.0 objects
346 #endif
347
348 GBool ok; // set up ok?
349 const char *pageRanges; // page ranges to render
350
351 friend class WinPDFPrinter;
352 };
353
354 #endif