1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
19 #include "xpdfconfig.h"
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 imgLLXA = 0, int imgLLYA = 0,
58 int imgURXA = 0, int imgURYA = 0,
59 GBool manualCtrlA = gFalse);
61 // Open a PSOutputDev that will write to a generic stream.
62 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
63 XRef *xrefA, Catalog *catalog,
64 int firstPage, int lastPage, PSOutMode modeA,
65 int imgLLXA = 0, int imgLLYA = 0,
66 int imgURXA = 0, int imgURYA = 0,
67 GBool manualCtrlA = gFalse);
69 // Destructor -- writes the trailer and closes the file.
70 virtual ~PSOutputDev();
72 // Check if file was successfully created.
73 virtual GBool isOk() { return ok; }
75 //---- get info about output device
77 // Does this device use upside-down coordinates?
78 // (Upside-down means (0,0) is the top left corner of the page.)
79 virtual GBool upsideDown() { return gFalse; }
81 // Does this device use drawChar() or drawString()?
82 virtual GBool useDrawChar() { return gFalse; }
84 // Does this device use beginType3Char/endType3Char? Otherwise,
85 // text in Type 3 fonts will be drawn with drawChar/drawString.
86 virtual GBool interpretType3Chars() { return gFalse; }
88 //----- header/trailer (used only if manualCtrl is true)
90 // Write the document-level header.
91 void writeHeader(int firstPage, int lastPage,
92 PDFRectangle *mediaBox, PDFRectangle *cropBox);
94 // Write the Xpdf procset.
95 void writeXpdfProcset();
97 // Write the document-level setup.
98 void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
100 // Write the setup for the current page.
101 void writePageSetup();
103 // Write the trailer for the current page.
104 void writePageTrailer();
106 // Write the document trailer.
109 //----- initialization and control
112 virtual void startPage(int pageNum, GfxState *state);
115 virtual void endPage();
117 //----- save/restore graphics state
118 virtual void saveState(GfxState *state);
119 virtual void restoreState(GfxState *state);
121 //----- update graphics state
122 virtual void updateCTM(GfxState *state, double m11, double m12,
123 double m21, double m22, double m31, double m32);
124 virtual void updateLineDash(GfxState *state);
125 virtual void updateFlatness(GfxState *state);
126 virtual void updateLineJoin(GfxState *state);
127 virtual void updateLineCap(GfxState *state);
128 virtual void updateMiterLimit(GfxState *state);
129 virtual void updateLineWidth(GfxState *state);
130 virtual void updateFillColor(GfxState *state);
131 virtual void updateStrokeColor(GfxState *state);
133 //----- update text state
134 virtual void updateFont(GfxState *state);
135 virtual void updateTextMat(GfxState *state);
136 virtual void updateCharSpace(GfxState *state);
137 virtual void updateRender(GfxState *state);
138 virtual void updateRise(GfxState *state);
139 virtual void updateWordSpace(GfxState *state);
140 virtual void updateHorizScaling(GfxState *state);
141 virtual void updateTextPos(GfxState *state);
142 virtual void updateTextShift(GfxState *state, double shift);
144 //----- path painting
145 virtual void stroke(GfxState *state);
146 virtual void fill(GfxState *state);
147 virtual void eoFill(GfxState *state);
149 //----- path clipping
150 virtual void clip(GfxState *state);
151 virtual void eoClip(GfxState *state);
154 virtual void drawString(GfxState *state, GString *s);
155 virtual void endTextObject(GfxState *state);
157 //----- image drawing
158 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
159 int width, int height, GBool invert,
161 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
162 int width, int height, GfxImageColorMap *colorMap,
163 int *maskColors, GBool inlineImg);
166 //----- OPI functions
167 virtual void opiBegin(GfxState *state, Dict *opiDict);
168 virtual void opiEnd(GfxState *state, Dict *opiDict);
171 //----- Type 3 font operators
172 virtual void type3D0(GfxState *state, double wx, double wy);
173 virtual void type3D1(GfxState *state, double wx, double wy,
174 double llx, double lly, double urx, double ury);
176 //----- PostScript XObjects
177 virtual void psXObject(Stream *psStream, Stream *level1Stream);
179 //----- miscellaneous
180 void setOffset(double x, double y)
181 { tx0 = x; ty0 = y; }
182 void setScale(double x, double y)
183 { xScale0 = x; yScale0 = y; }
184 void setRotate(int rotateA)
185 { rotate0 = rotateA; }
186 void setClip(double llx, double lly, double urx, double ury)
187 { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
188 void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
190 { underlayCbk = cbk; underlayCbkData = data; }
191 void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
193 { overlayCbk = cbk; overlayCbkData = data; }
197 void init(PSOutputFunc outputFuncA, void *outputStreamA,
198 PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
199 int firstPage, int lastPage, PSOutMode modeA,
200 int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
202 void setupResources(Dict *resDict);
203 void setupFonts(Dict *resDict);
204 void setupFont(GfxFont *font, Dict *parentResDict);
205 void setupEmbeddedType1Font(Ref *id, GString *psName);
206 void setupExternalType1Font(GString *fileName, GString *psName);
207 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
208 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
209 void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
210 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
211 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
212 void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
213 void setupImages(Dict *resDict);
214 void setupImage(Ref id, Stream *str);
215 void addProcessColor(double c, double m, double y, double k);
216 void addCustomColor(GfxSeparationColorSpace *sepCS);
217 void doPath(GfxPath *path);
218 void doImageL1(Object *ref, GfxImageColorMap *colorMap,
219 GBool invert, GBool inlineImg,
220 Stream *str, int width, int height, int len);
221 void doImageL1Sep(GfxImageColorMap *colorMap,
222 GBool invert, GBool inlineImg,
223 Stream *str, int width, int height, int len);
224 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
225 GBool invert, GBool inlineImg,
226 Stream *str, int width, int height, int len);
227 void dumpColorSpaceL2(GfxColorSpace *colorSpace);
229 void opiBegin20(GfxState *state, Dict *dict);
230 void opiBegin13(GfxState *state, Dict *dict);
231 void opiTransform(GfxState *state, double x0, double y0,
232 double *x1, double *y1);
233 GBool getFileSpec(Object *fileSpec, Object *fileName);
235 void writePSChar(char c);
236 void writePS(char *s);
237 void writePSFmt(const char *fmt, ...);
238 void writePSString(GString *s);
239 void writePSName(char *s);
240 GString *filterPSName(GString *name);
242 PSLevel level; // PostScript level (1, 2, separation)
243 PSOutMode mode; // PostScript mode (PS, EPS, form)
244 int paperWidth; // width of paper, in pts
245 int paperHeight; // height of paper, in pts
246 int imgLLX, imgLLY, // imageable area, in pts
249 PSOutputFunc outputFunc;
251 PSFileType fileType; // file / pipe / stdout
253 int seqPage; // current sequential page number
254 void (*underlayCbk)(PSOutputDev *psOut, void *data);
255 void *underlayCbkData;
256 void (*overlayCbk)(PSOutputDev *psOut, void *data);
257 void *overlayCbkData;
259 XRef *xref; // the xref table for this PDF file
261 Ref *fontIDs; // list of object IDs of all used fonts
262 int fontIDLen; // number of entries in fontIDs array
263 int fontIDSize; // size of fontIDs array
264 Ref *fontFileIDs; // list of object IDs of all embedded fonts
265 int fontFileIDLen; // number of entries in fontFileIDs array
266 int fontFileIDSize; // size of fontFileIDs array
267 GString **fontFileNames; // list of names of all embedded external fonts
268 int fontFileNameLen; // number of entries in fontFileNames array
269 int fontFileNameSize; // size of fontFileNames array
270 int nextTrueTypeNum; // next unique number to append to a TrueType
272 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
273 int font16EncLen; // number of entries in font16Enc array
274 int font16EncSize; // size of font16Enc array
275 GList *xobjStack; // stack of XObject dicts currently being
277 int numSaves; // current number of gsaves
279 double tx0, ty0; // global translation
280 double xScale0, yScale0; // global scaling
281 int rotate0; // rotation angle (0, 90, 180, 270)
282 double clipLLX0, clipLLY0,
284 double tx, ty; // global translation for current page
285 double xScale, yScale; // global scaling for current page
286 int rotate; // rotation angle for current page
288 GString *embFontList; // resource comments for embedded fonts
290 int processColors; // used process colors
291 PSOutCustomColor // used custom colors
294 GBool haveTextClip; // set if text has been drawn with a
295 // clipping render mode
297 GBool inType3Char; // inside a Type 3 CharProc
298 GString *t3String; // Type 3 content string
299 double t3WX, t3WY, // Type 3 character parameters
300 t3LLX, t3LLY, t3URX, t3URY;
301 GBool t3Cacheable; // cleared if char is not cacheable
304 int opi13Nest; // nesting level of OPI 1.3 objects
305 int opi20Nest; // nesting level of OPI 2.0 objects
308 GBool ok; // set up ok?
311 friend class WinPDFPrinter;