1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
21 #include "GlobalParams.h"
22 #include "OutputDev.h"
28 class GfxSeparationColorSpace
;
31 class PSOutCustomColor
;
33 //------------------------------------------------------------------------
35 //------------------------------------------------------------------------
44 psFile
, // write to file
45 psPipe
, // write to pipe
46 psStdout
, // write to stdout
47 psGeneric
// write to a generic stream
50 typedef void (*PSOutputFunc
)(void *stream
, char *data
, int len
);
52 class PSOutputDev
: public OutputDev
{
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);
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);
72 // Destructor -- writes the trailer and closes the file.
73 virtual ~PSOutputDev();
75 // Check if file was successfully created.
76 virtual GBool
isOk() { return ok
; }
78 //---- get info about output device
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
; }
84 // Does this device use drawChar() or drawString()?
85 virtual GBool
useDrawChar() { return gFalse
; }
87 // Does this device use tilingPatternFill()? If this returns false,
88 // tiling pattern fills will be reduced to a series of other drawing
90 virtual GBool
useTilingPatternFill() { return gTrue
; }
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
; }
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
; }
102 //----- header/trailer (used only if manualCtrl is true)
104 // Write the document-level header.
105 void writeHeader(int firstPage
, int lastPage
,
106 PDFRectangle
*mediaBox
, PDFRectangle
*cropBox
,
109 // Write the Xpdf procset.
110 void writeXpdfProcset();
112 // Write the document-level setup.
113 void writeDocSetup(Catalog
*catalog
, int firstPage
, int lastPage
);
115 // Write the trailer for the current page.
116 void writePageTrailer();
118 // Write the document trailer.
121 //----- initialization and control
124 virtual GBool
startPage(int pageNum
, GfxState
*state
);
127 virtual void endPage();
129 //----- save/restore graphics state
130 virtual void saveState(GfxState
*state
);
131 virtual void restoreState(GfxState
*state
);
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
);
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
);
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
);
174 //----- path clipping
175 virtual void clip(GfxState
*state
);
176 virtual void eoClip(GfxState
*state
);
179 virtual void drawString(GfxState
*state
, GString
*s
);
180 virtual void endTextObject(GfxState
*state
);
182 //----- image drawing
183 virtual void drawImageMask(GfxState
*state
, Object
*ref
, Stream
*str
,
184 int width
, int height
, GBool invert
,
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
,
196 //----- OPI functions
197 virtual void opiBegin(GfxState
*state
, Dict
*opiDict
);
198 virtual void opiEnd(GfxState
*state
, Dict
*opiDict
);
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
);
206 //----- PostScript XObjects
207 virtual void psXObject(Stream
*psStream
, Stream
*level1Stream
);
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
),
220 { underlayCbk
= cbk
; underlayCbkData
= data
; }
221 void setOverlayCbk(void (*cbk
)(PSOutputDev
*psOut
, void *data
),
223 { overlayCbk
= cbk
; overlayCbkData
= data
; }
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
);
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
);
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
);
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
285 PSOutputFunc outputFunc
;
287 PSFileType fileType
; // file / pipe / stdout
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
;
295 XRef
*xref
; // the xref table for this PDF file
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
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
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
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
,
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)
328 GString
*embFontList
; // resource comments for embedded fonts
330 int processColors
; // used process colors
331 PSOutCustomColor
// used custom colors
334 GBool haveTextClip
; // set if text has been drawn with a
335 // clipping render mode
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
344 int opi13Nest
; // nesting level of OPI 1.3 objects
345 int opi20Nest
; // nesting level of OPI 2.0 objects
348 GBool ok
; // set up ok?
349 const char *pageRanges
; // page ranges to render
351 friend class WinPDFPrinter
;