1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
21 #include "GlobalParams.h"
22 #include "OutputDev.h"
27 class GfxSeparationColorSpace;
30 class PSOutCustomColor;
32 //------------------------------------------------------------------------
34 //------------------------------------------------------------------------
43 psFile, // write to file
44 psPipe, // write to pipe
45 psStdout, // write to stdout
46 psGeneric // write to a generic stream
49 typedef void (*PSOutputFunc)(void *stream, char *data, int len);
51 class PSOutputDev: public OutputDev {
54 // Open a PostScript output file, and write the prolog.
55 PSOutputDev(char *fileName, XRef *xrefA, Catalog *catalog,
56 int firstPage, int lastPage, PSOutMode modeA,
57 int paperWidthA = 0, int paperHeightA = 0,
58 GBool manualCtrlA = gFalse);
60 // Open a PSOutputDev that will write to a generic stream.
61 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
62 XRef *xrefA, Catalog *catalog,
63 int firstPage, int lastPage, PSOutMode modeA,
64 int paperWidthA = 0, int paperHeightA = 0,
65 GBool manualCtrlA = gFalse);
67 // Destructor -- writes the trailer and closes the file.
68 virtual ~PSOutputDev();
70 // Check if file was successfully created.
71 virtual GBool isOk() { return ok; }
73 //---- get info about output device
75 // Does this device use upside-down coordinates?
76 // (Upside-down means (0,0) is the top left corner of the page.)
77 virtual GBool upsideDown() { return gFalse; }
79 // Does this device use drawChar() or drawString()?
80 virtual GBool useDrawChar() { return gFalse; }
82 // Does this device use beginType3Char/endType3Char? Otherwise,
83 // text in Type 3 fonts will be drawn with drawChar/drawString.
84 virtual GBool interpretType3Chars() { return gFalse; }
86 //----- header/trailer (used only if manualCtrl is true)
88 // Write the document-level header.
89 void writeHeader(int firstPage, int lastPage, PDFRectangle *box);
91 // Write the Xpdf procset.
92 void writeXpdfProcset();
94 // Write the document-level setup.
95 void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
97 // Write the setup for the current page.
98 void writePageSetup();
100 // Write the trailer for the current page.
101 void writePageTrailer();
103 // Write the document trailer.
106 //----- initialization and control
109 virtual void startPage(int pageNum, GfxState *state);
112 virtual void endPage();
114 //----- save/restore graphics state
115 virtual void saveState(GfxState *state);
116 virtual void restoreState(GfxState *state);
118 //----- update graphics state
119 virtual void updateCTM(GfxState *state, double m11, double m12,
120 double m21, double m22, double m31, double m32);
121 virtual void updateLineDash(GfxState *state);
122 virtual void updateFlatness(GfxState *state);
123 virtual void updateLineJoin(GfxState *state);
124 virtual void updateLineCap(GfxState *state);
125 virtual void updateMiterLimit(GfxState *state);
126 virtual void updateLineWidth(GfxState *state);
127 virtual void updateFillColor(GfxState *state);
128 virtual void updateStrokeColor(GfxState *state);
130 //----- update text state
131 virtual void updateFont(GfxState *state);
132 virtual void updateTextMat(GfxState *state);
133 virtual void updateCharSpace(GfxState *state);
134 virtual void updateRender(GfxState *state);
135 virtual void updateRise(GfxState *state);
136 virtual void updateWordSpace(GfxState *state);
137 virtual void updateHorizScaling(GfxState *state);
138 virtual void updateTextPos(GfxState *state);
139 virtual void updateTextShift(GfxState *state, double shift);
141 //----- path painting
142 virtual void stroke(GfxState *state);
143 virtual void fill(GfxState *state);
144 virtual void eoFill(GfxState *state);
146 //----- path clipping
147 virtual void clip(GfxState *state);
148 virtual void eoClip(GfxState *state);
151 virtual void drawString(GfxState *state, GString *s);
152 virtual void endTextObject(GfxState *state);
154 //----- image drawing
155 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
156 int width, int height, GBool invert,
158 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
159 int width, int height, GfxImageColorMap *colorMap,
160 int *maskColors, GBool inlineImg);
163 //----- OPI functions
164 virtual void opiBegin(GfxState *state, Dict *opiDict);
165 virtual void opiEnd(GfxState *state, Dict *opiDict);
168 //----- Type 3 font operators
169 virtual void type3D0(GfxState *state, double wx, double wy);
170 virtual void type3D1(GfxState *state, double wx, double wy,
171 double llx, double lly, double urx, double ury);
173 //----- PostScript XObjects
174 virtual void psXObject(Stream *psStream, Stream *level1Stream);
176 //----- miscellaneous
177 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
179 { underlayCbk = cbk; underlayCbkData = data; }
180 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
182 { overlayCbk = cbk; overlayCbkData = data; }
186 void init(PSOutputFunc outputFuncA, void *outputStreamA,
187 PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
188 int firstPage, int lastPage, PSOutMode modeA,
189 int paperWidthA, int paperHeightA,
191 void setupResources(Dict *resDict);
192 void setupFonts(Dict *resDict);
193 void setupFont(GfxFont *font, Dict *parentResDict);
194 void setupEmbeddedType1Font(Ref *id, GString *psName);
195 void setupExternalType1Font(GString *fileName, GString *psName);
196 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
197 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
198 void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
199 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
200 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
201 void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
202 void setupImages(Dict *resDict);
203 void setupImage(Ref id, Stream *str);
204 void addProcessColor(double c, double m, double y, double k);
205 void addCustomColor(GfxSeparationColorSpace *sepCS);
206 void doPath(GfxPath *path);
207 void doImageL1(GfxImageColorMap *colorMap,
208 GBool invert, GBool inlineImg,
209 Stream *str, int width, int height, int len);
210 void doImageL1Sep(GfxImageColorMap *colorMap,
211 GBool invert, GBool inlineImg,
212 Stream *str, int width, int height, int len);
213 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
214 GBool invert, GBool inlineImg,
215 Stream *str, int width, int height, int len);
216 void dumpColorSpaceL2(GfxColorSpace *colorSpace);
218 void opiBegin20(GfxState *state, Dict *dict);
219 void opiBegin13(GfxState *state, Dict *dict);
220 void opiTransform(GfxState *state, double x0, double y0,
221 double *x1, double *y1);
222 GBool getFileSpec(Object *fileSpec, Object *fileName);
224 void writePSChar(char c);
225 void writePS(char *s);
226 void writePSFmt(const char *fmt, ...);
227 void writePSString(GString *s);
228 void writePSName(char *s);
229 GString *filterPSName(GString *name);
231 PSLevel level; // PostScript level (1, 2, separation)
232 PSOutMode mode; // PostScript mode (PS, EPS, form)
233 int paperWidth; // width of paper, in pts
234 int paperHeight; // height of paper, in pts
236 PSOutputFunc outputFunc;
238 PSFileType fileType; // file / pipe / stdout
240 int seqPage; // current sequential page number
241 void (*underlayCbk)(PSOutputDev *psOut, void *data);
242 void *underlayCbkData;
243 void (*overlayCbk)(PSOutputDev *psOut, void *data);
244 void *overlayCbkData;
246 XRef *xref; // the xref table for this PDF file
248 Ref *fontIDs; // list of object IDs of all used fonts
249 int fontIDLen; // number of entries in fontIDs array
250 int fontIDSize; // size of fontIDs array
251 Ref *fontFileIDs; // list of object IDs of all embedded fonts
252 int fontFileIDLen; // number of entries in fontFileIDs array
253 int fontFileIDSize; // size of fontFileIDs array
254 GString **fontFileNames; // list of names of all embedded external fonts
255 int fontFileNameLen; // number of entries in fontFileNames array
256 int fontFileNameSize; // size of fontFileNames array
257 int nextTrueTypeNum; // next unique number to append to a TrueType
259 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
260 int font16EncLen; // number of entries in font16Enc array
261 int font16EncSize; // size of font16Enc array
262 GList *xobjStack; // stack of XObject dicts currently being
264 int numSaves; // current number of gsaves
266 double tx, ty; // global translation
267 double xScale, yScale; // global scaling
268 GBool landscape; // true for landscape, false for portrait
270 GString *embFontList; // resource comments for embedded fonts
272 int processColors; // used process colors
273 PSOutCustomColor // used custom colors
276 GBool haveTextClip; // set if text has been drawn with a
277 // clipping render mode
279 GBool inType3Char; // inside a Type 3 CharProc
280 GString *t3String; // Type 3 content string
281 double t3WX, t3WY, // Type 3 character parameters
282 t3LLX, t3LLY, t3URX, t3URY;
283 GBool t3Cacheable; // cleared if char is not cacheable
286 int opi13Nest; // nesting level of OPI 1.3 objects
287 int opi20Nest; // nesting level of OPI 2.0 objects
290 GBool ok; // set up ok?
293 friend class WinPDFPrinter;