1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
19 #include "OutputDev.h"
25 //------------------------------------------------------------------------
27 //------------------------------------------------------------------------
29 // Generate Level 1 PostScript?
30 extern GBool psOutLevel1;
32 // Generate Level 1 separable PostScript?
33 extern GBool psOutLevel1Sep;
35 // Generate Encapsulated PostScript?
36 extern GBool psOutEPS;
39 // Generate OPI comments?
40 extern GBool psOutOPI;
44 extern int paperWidth;
45 extern int paperHeight;
47 //------------------------------------------------------------------------
49 //------------------------------------------------------------------------
52 psFile, // write to file
53 psPipe, // write to pipe
54 psStdout // write to stdout
57 class PSOutputDev: public OutputDev {
60 // Open a PostScript output file, and write the prolog.
61 PSOutputDev(char *fileName, Catalog *catalog,
62 int firstPage, int lastPage,
63 GBool embedType11, GBool doForm1);
65 // Destructor -- writes the trailer and closes the file.
66 virtual ~PSOutputDev();
68 // Check if file was successfully created.
69 virtual GBool isOk() { return ok; }
71 //---- get info about output device
73 // Does this device use upside-down coordinates?
74 // (Upside-down means (0,0) is the top left corner of the page.)
75 virtual GBool upsideDown() { return gFalse; }
77 // Does this device use drawChar() or drawString()?
78 virtual GBool useDrawChar() { return gFalse; }
80 //----- initialization and control
83 virtual void startPage(int pageNum, GfxState *state);
86 virtual void endPage();
88 //----- save/restore graphics state
89 virtual void saveState(GfxState *state);
90 virtual void restoreState(GfxState *state);
92 //----- update graphics state
93 virtual void updateCTM(GfxState *state, double m11, double m12,
94 double m21, double m22, double m31, double m32);
95 virtual void updateLineDash(GfxState *state);
96 virtual void updateFlatness(GfxState *state);
97 virtual void updateLineJoin(GfxState *state);
98 virtual void updateLineCap(GfxState *state);
99 virtual void updateMiterLimit(GfxState *state);
100 virtual void updateLineWidth(GfxState *state);
101 virtual void updateFillColor(GfxState *state);
102 virtual void updateStrokeColor(GfxState *state);
104 //----- update text state
105 virtual void updateFont(GfxState *state);
106 virtual void updateTextMat(GfxState *state);
107 virtual void updateCharSpace(GfxState *state);
108 virtual void updateRender(GfxState *state);
109 virtual void updateRise(GfxState *state);
110 virtual void updateWordSpace(GfxState *state);
111 virtual void updateHorizScaling(GfxState *state);
112 virtual void updateTextPos(GfxState *state);
113 virtual void updateTextShift(GfxState *state, double shift);
115 //----- path painting
116 virtual void stroke(GfxState *state);
117 virtual void fill(GfxState *state);
118 virtual void eoFill(GfxState *state);
120 //----- path clipping
121 virtual void clip(GfxState *state);
122 virtual void eoClip(GfxState *state);
125 virtual void drawString(GfxState *state, GString *s);
126 virtual void drawString16(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,
137 //----- OPI functions
138 virtual void opiBegin(GfxState *state, Dict *opiDict);
139 virtual void opiEnd(GfxState *state, Dict *opiDict);
144 void setupResources(Dict *resDict);
145 void setupFonts(Dict *resDict);
146 void setupFont(GfxFont *font);
147 void setupEmbeddedType1Font(Ref *id, char *psName);
148 void setupEmbeddedType1Font(GString *fileName, char *psName);
149 void setupEmbeddedType1CFont(GfxFont *font, Ref *id, char *psName);
150 void setupImages(Dict *resDict);
151 void setupImage(Ref id, Stream *str);
152 void doPath(GfxPath *path);
153 void doImageL1(GfxImageColorMap *colorMap,
154 GBool invert, GBool inlineImg,
155 Stream *str, int width, int height, int len);
156 void doImageL1Sep(GfxImageColorMap *colorMap,
157 GBool invert, GBool inlineImg,
158 Stream *str, int width, int height, int len);
159 void doImageL2(Object *ref, GfxImageColorMap *colorMap,
160 GBool invert, GBool inlineImg,
161 Stream *str, int width, int height, int len);
162 void dumpColorSpaceL2(GfxColorSpace *colorSpace);
163 void opiBegin20(GfxState *state, Dict *dict);
164 void opiBegin13(GfxState *state, Dict *dict);
165 void opiTransform(GfxState *state, double x0, double y0,
166 double *x1, double *y1);
167 GBool getFileSpec(Object *fileSpec, Object *fileName);
168 void writePS(const char *fmt, ...);
169 void writePSString(GString *s);
171 GBool embedType1; // embed Type 1 fonts?
172 GBool doForm; // generate a form?
174 FILE *f; // PostScript file
175 PSFileType fileType; // file / pipe / stdout
176 int seqPage; // current sequential page number
178 Ref *fontIDs; // list of object IDs of all used fonts
179 int fontIDLen; // number of entries in fontIDs array
180 int fontIDSize; // size of fontIDs array
181 Ref *fontFileIDs; // list of object IDs of all embedded fonts
182 int fontFileIDLen; // number of entries in fontFileIDs array
183 int fontFileIDSize; // size of fontFileIDs array
184 GString **fontFileNames; // list of names of all embedded external fonts
185 int fontFileNameLen; // number of entries in fontFileNames array
186 int fontFileNameSize; // size of fontFileNames array
188 double tx, ty; // global translation
189 double xScale, yScale; // global scaling
190 GBool landscape; // true for landscape, false for portrait
192 GString *embFontList; // resource comments for embedded fonts
195 int opi13Nest; // nesting level of OPI 1.3 objects
196 int opi20Nest; // nesting level of OPI 2.0 objects
199 GBool type3Warning; // only show the Type 3 font warning once
201 GBool ok; // set up ok?