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;
29 class PSOutCustomColor;
31 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
42 psFile, // write to file
43 psPipe, // write to pipe
44 psStdout, // write to stdout
45 psGeneric // write to a generic stream
48 typedef void (*PSOutputFunc)(void *stream, char *data, int len);
50 class PSOutputDev: public OutputDev {
53 // Open a PostScript output file, and write the prolog.
54 PSOutputDev(char *fileName, XRef *xrefA, Catalog *catalog,
55 int firstPage, int lastPage, PSOutMode modeA);
57 // Open a PSOutputDev that will write to a generic stream.
58 PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
59 XRef *xrefA, Catalog *catalog,
60 int firstPage, int lastPage, PSOutMode modeA);
62 // Destructor -- writes the trailer and closes the file.
63 virtual ~PSOutputDev();
65 // Check if file was successfully created.
66 virtual GBool isOk() { return ok; }
68 //---- get info about output device
70 // Does this device use upside-down coordinates?
71 // (Upside-down means (0,0) is the top left corner of the page.)
72 virtual GBool upsideDown() { return gFalse; }
74 // Does this device use drawChar() or drawString()?
75 virtual GBool useDrawChar() { return gFalse; }
77 // Does this device use beginType3Char/endType3Char? Otherwise,
78 // text in Type 3 fonts will be drawn with drawChar/drawString.
79 virtual GBool interpretType3Chars() { return gFalse; }
81 //----- initialization and control
84 virtual void startPage(int pageNum, GfxState *state);
87 virtual void endPage();
89 //----- save/restore graphics state
90 virtual void saveState(GfxState *state);
91 virtual void restoreState(GfxState *state);
93 //----- update graphics state
94 virtual void updateCTM(GfxState *state, double m11, double m12,
95 double m21, double m22, double m31, double m32);
96 virtual void updateLineDash(GfxState *state);
97 virtual void updateFlatness(GfxState *state);
98 virtual void updateLineJoin(GfxState *state);
99 virtual void updateLineCap(GfxState *state);
100 virtual void updateMiterLimit(GfxState *state);
101 virtual void updateLineWidth(GfxState *state);
102 virtual void updateFillColor(GfxState *state);
103 virtual void updateStrokeColor(GfxState *state);
105 //----- update text state
106 virtual void updateFont(GfxState *state);
107 virtual void updateTextMat(GfxState *state);
108 virtual void updateCharSpace(GfxState *state);
109 virtual void updateRender(GfxState *state);
110 virtual void updateRise(GfxState *state);
111 virtual void updateWordSpace(GfxState *state);
112 virtual void updateHorizScaling(GfxState *state);
113 virtual void updateTextPos(GfxState *state);
114 virtual void updateTextShift(GfxState *state, double shift);
116 //----- path painting
117 virtual void stroke(GfxState *state);
118 virtual void fill(GfxState *state);
119 virtual void eoFill(GfxState *state);
121 //----- path clipping
122 virtual void clip(GfxState *state);
123 virtual void eoClip(GfxState *state);
126 virtual void drawString(GfxState *state, GString *s);
128 //----- image drawing
129 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
130 int width, int height, GBool invert,
132 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
133 int width, int height, GfxImageColorMap *colorMap,
134 int *maskColors, GBool inlineImg);
137 //----- OPI functions
138 virtual void opiBegin(GfxState *state, Dict *opiDict);
139 virtual void opiEnd(GfxState *state, Dict *opiDict);
142 //----- Type 3 font operators
143 virtual void type3D0(GfxState *state, double wx, double wy);
144 virtual void type3D1(GfxState *state, double wx, double wy,
145 double llx, double lly, double urx, double ury);
147 //----- PostScript XObjects
148 virtual void psXObject(Stream *psStream, Stream *level1Stream);
153 void init(PSOutputFunc outputFuncA, void *outputStreamA,
154 PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
155 int firstPage, int lastPage, PSOutMode modeA);
156 void setupResources(Dict *resDict);
157 void setupFonts(Dict *resDict);
158 void setupFont(GfxFont *font, Dict *parentResDict);
159 void setupEmbeddedType1Font(Ref *id, char *psName);
160 void setupExternalType1Font(GString *fileName, char *psName);
161 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, char *psName);
162 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, char *psName);
163 void setupExternalTrueTypeFont(GfxFont *font, char *psName);
164 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, char *psName);
165 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, char *psName);
166 void setupType3Font(GfxFont *font, char *psName, Dict *parentResDict);
167 void setupImages(Dict *resDict);
168 void setupImage(Ref id, Stream *str);
169 void addProcessColor(double c, double m, double y, double k);
170 void addCustomColor(GfxSeparationColorSpace *sepCS);
171 void doPath(GfxPath *path);
172 void doImageL1(GfxImageColorMap *colorMap,
173 GBool invert, GBool inlineImg,
174 Stream *str, int width, int height, int len);
175 void doImageL1Sep(GfxImageColorMap *colorMap,
176 GBool invert, GBool inlineImg,
177 Stream *str, int width, int height, int len);
178 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
179 GBool invert, GBool inlineImg,
180 Stream *str, int width, int height, int len);
181 void dumpColorSpaceL2(GfxColorSpace *colorSpace);
183 void opiBegin20(GfxState *state, Dict *dict);
184 void opiBegin13(GfxState *state, Dict *dict);
185 void opiTransform(GfxState *state, double x0, double y0,
186 double *x1, double *y1);
187 GBool getFileSpec(Object *fileSpec, Object *fileName);
189 void writePSChar(char c);
190 void writePS(char *s);
191 void writePSFmt(const char *fmt, ...);
192 void writePSString(GString *s);
193 void writePSName(char *s);
194 GString *filterPSName(GString *name);
196 PSLevel level; // PostScript level (1, 2, separation)
197 PSOutMode mode; // PostScript mode (PS, EPS, form)
198 int paperWidth; // width of paper, in pts
199 int paperHeight; // height of paper, in pts
201 PSOutputFunc outputFunc;
203 PSFileType fileType; // file / pipe / stdout
204 int seqPage; // current sequential page number
206 XRef *xref; // the xref table for this PDF file
208 Ref *fontIDs; // list of object IDs of all used fonts
209 int fontIDLen; // number of entries in fontIDs array
210 int fontIDSize; // size of fontIDs array
211 Ref *fontFileIDs; // list of object IDs of all embedded fonts
212 int fontFileIDLen; // number of entries in fontFileIDs array
213 int fontFileIDSize; // size of fontFileIDs array
214 GString **fontFileNames; // list of names of all embedded external fonts
215 int fontFileNameLen; // number of entries in fontFileNames array
216 int fontFileNameSize; // size of fontFileNames array
217 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
218 int font16EncLen; // number of entries in font16Enc array
219 int font16EncSize; // size of font16Enc array
220 GList *xobjStack; // stack of XObject dicts currently being
223 double tx, ty; // global translation
224 double xScale, yScale; // global scaling
225 GBool landscape; // true for landscape, false for portrait
227 GString *embFontList; // resource comments for embedded fonts
229 int processColors; // used process colors
230 PSOutCustomColor // used custom colors
233 GBool inType3Char; // inside a Type 3 CharProc
234 GString *t3String; // Type 3 content string
235 double t3WX, t3WY, // Type 3 character parameters
236 t3LLX, t3LLY, t3URX, t3URY;
237 GBool t3Cacheable; // cleared if char is not cacheable
240 int opi13Nest; // nesting level of OPI 1.3 objects
241 int opi20Nest; // nesting level of OPI 2.0 objects
244 GBool ok; // set up ok?