1 //========================================================================
5 // Copyright 1996-2002 Glyph & Cog, LLC
7 //========================================================================
19 #include "GlobalParams.h"
20 #include "OutputDev.h"
25 class GfxSeparationColorSpace;
27 class PSOutCustomColor;
29 //------------------------------------------------------------------------
31 //------------------------------------------------------------------------
40 psFile, // write to file
41 psPipe, // write to pipe
42 psStdout // write to stdout
45 class PSOutputDev: public OutputDev {
48 // Open a PostScript output file, and write the prolog.
49 PSOutputDev(char *fileName, XRef *xrefA, Catalog *catalog,
50 int firstPage, int lastPage, PSOutMode modeA);
52 // Destructor -- writes the trailer and closes the file.
53 virtual ~PSOutputDev();
55 // Check if file was successfully created.
56 virtual GBool isOk() { return ok; }
58 //---- get info about output device
60 // Does this device use upside-down coordinates?
61 // (Upside-down means (0,0) is the top left corner of the page.)
62 virtual GBool upsideDown() { return gFalse; }
64 // Does this device use drawChar() or drawString()?
65 virtual GBool useDrawChar() { return gFalse; }
67 // Does this device use beginType3Char/endType3Char? Otherwise,
68 // text in Type 3 fonts will be drawn with drawChar/drawString.
69 virtual GBool interpretType3Chars() { return gFalse; }
71 //----- initialization and control
74 virtual void startPage(int pageNum, GfxState *state);
77 virtual void endPage();
79 //----- save/restore graphics state
80 virtual void saveState(GfxState *state);
81 virtual void restoreState(GfxState *state);
83 //----- update graphics state
84 virtual void updateCTM(GfxState *state, double m11, double m12,
85 double m21, double m22, double m31, double m32);
86 virtual void updateLineDash(GfxState *state);
87 virtual void updateFlatness(GfxState *state);
88 virtual void updateLineJoin(GfxState *state);
89 virtual void updateLineCap(GfxState *state);
90 virtual void updateMiterLimit(GfxState *state);
91 virtual void updateLineWidth(GfxState *state);
92 virtual void updateFillColor(GfxState *state);
93 virtual void updateStrokeColor(GfxState *state);
95 //----- update text state
96 virtual void updateFont(GfxState *state);
97 virtual void updateTextMat(GfxState *state);
98 virtual void updateCharSpace(GfxState *state);
99 virtual void updateRender(GfxState *state);
100 virtual void updateRise(GfxState *state);
101 virtual void updateWordSpace(GfxState *state);
102 virtual void updateHorizScaling(GfxState *state);
103 virtual void updateTextPos(GfxState *state);
104 virtual void updateTextShift(GfxState *state, double shift);
106 //----- path painting
107 virtual void stroke(GfxState *state);
108 virtual void fill(GfxState *state);
109 virtual void eoFill(GfxState *state);
111 //----- path clipping
112 virtual void clip(GfxState *state);
113 virtual void eoClip(GfxState *state);
116 virtual void drawString(GfxState *state, GString *s);
118 //----- image drawing
119 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
120 int width, int height, GBool invert,
122 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
123 int width, int height, GfxImageColorMap *colorMap,
124 int *maskColors, GBool inlineImg);
127 //----- OPI functions
128 virtual void opiBegin(GfxState *state, Dict *opiDict);
129 virtual void opiEnd(GfxState *state, Dict *opiDict);
132 //----- Type 3 font operators
133 virtual void type3D0(GfxState *state, double wx, double wy);
134 virtual void type3D1(GfxState *state, double wx, double wy,
135 double llx, double lly, double urx, double ury);
137 //----- PostScript XObjects
138 virtual void psXObject(Stream *psStream, Stream *level1Stream);
142 void setupResources(Dict *resDict);
143 void setupFonts(Dict *resDict);
144 void setupFont(GfxFont *font, Dict *parentResDict);
145 void setupEmbeddedType1Font(Ref *id, char *psName);
146 void setupExternalType1Font(GString *fileName, char *psName);
147 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, char *psName);
148 void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, char *psName);
149 void setupExternalTrueTypeFont(GfxFont *font, char *psName);
150 void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, char *psName);
151 void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, char *psName);
152 void setupType3Font(GfxFont *font, char *psName, Dict *parentResDict);
153 void setupImages(Dict *resDict);
154 void setupImage(Ref id, Stream *str);
155 void addProcessColor(double c, double m, double y, double k);
156 void addCustomColor(GfxSeparationColorSpace *sepCS);
157 void doPath(GfxPath *path);
158 void doImageL1(GfxImageColorMap *colorMap,
159 GBool invert, GBool inlineImg,
160 Stream *str, int width, int height, int len);
161 void doImageL1Sep(GfxImageColorMap *colorMap,
162 GBool invert, GBool inlineImg,
163 Stream *str, int width, int height, int len);
164 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
165 GBool invert, GBool inlineImg,
166 Stream *str, int width, int height, int len);
167 void dumpColorSpaceL2(GfxColorSpace *colorSpace);
169 void opiBegin20(GfxState *state, Dict *dict);
170 void opiBegin13(GfxState *state, Dict *dict);
171 void opiTransform(GfxState *state, double x0, double y0,
172 double *x1, double *y1);
173 GBool getFileSpec(Object *fileSpec, Object *fileName);
175 void writePS(const char *fmt, ...);
176 void writePSString(GString *s);
177 void writePSChar(char c);
178 GString *filterPSName(GString *name);
180 PSLevel level; // PostScript level (1, 2, separation)
181 PSOutMode mode; // PostScript mode (PS, EPS, form)
182 int paperWidth; // width of paper, in pts
183 int paperHeight; // height of paper, in pts
185 FILE *f; // PostScript file
186 PSFileType fileType; // file / pipe / stdout
187 int seqPage; // current sequential page number
189 XRef *xref; // the xref table for this PDF file
191 Ref *fontIDs; // list of object IDs of all used fonts
192 int fontIDLen; // number of entries in fontIDs array
193 int fontIDSize; // size of fontIDs array
194 Ref *fontFileIDs; // list of object IDs of all embedded fonts
195 int fontFileIDLen; // number of entries in fontFileIDs array
196 int fontFileIDSize; // size of fontFileIDs array
197 GString **fontFileNames; // list of names of all embedded external fonts
198 int fontFileNameLen; // number of entries in fontFileNames array
199 int fontFileNameSize; // size of fontFileNames array
200 PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
201 int font16EncLen; // number of entries in font16Enc array
202 int font16EncSize; // size of font16Enc array
204 double tx, ty; // global translation
205 double xScale, yScale; // global scaling
206 GBool landscape; // true for landscape, false for portrait
208 GString *embFontList; // resource comments for embedded fonts
210 int processColors; // used process colors
211 PSOutCustomColor // used custom colors
214 GBool inType3Char; // inside a Type 3 CharProc
215 GString *t3String; // Type 3 content string
216 double t3WX, t3WY, // Type 3 character parameters
217 t3LLX, t3LLY, t3URX, t3URY;
218 GBool t3Cacheable; // cleared if char is not cacheable
221 int opi13Nest; // nesting level of OPI 1.3 objects
222 int opi20Nest; // nesting level of OPI 2.0 objects
225 GBool ok; // set up ok?