]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/PSOutputDev.h
Imported Xpdf 2.03 and fixed build.
[evince.git] / pdf / xpdf / PSOutputDev.h
1 //========================================================================
2 //
3 // PSOutputDev.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef PSOUTPUTDEV_H
10 #define PSOUTPUTDEV_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include <stddef.h>
19 #include "config.h"
20 #include "Object.h"
21 #include "GlobalParams.h"
22 #include "OutputDev.h"
23
24 class GfxPath;
25 class GfxFont;
26 class GfxColorSpace;
27 class GfxSeparationColorSpace;
28 class PDFRectangle;
29 struct PSFont16Enc;
30 class PSOutCustomColor;
31
32 //------------------------------------------------------------------------
33 // PSOutputDev
34 //------------------------------------------------------------------------
35
36 enum PSOutMode {
37   psModePS,
38   psModeEPS,
39   psModeForm
40 };
41
42 enum PSFileType {
43   psFile,                       // write to file
44   psPipe,                       // write to pipe
45   psStdout,                     // write to stdout
46   psGeneric                     // write to a generic stream
47 };
48
49 typedef void (*PSOutputFunc)(void *stream, char *data, int len);
50
51 class PSOutputDev: public OutputDev {
52 public:
53
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);
59
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);
66
67   // Destructor -- writes the trailer and closes the file.
68   virtual ~PSOutputDev();
69
70   // Check if file was successfully created.
71   virtual GBool isOk() { return ok; }
72
73   //---- get info about output device
74
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; }
78
79   // Does this device use drawChar() or drawString()?
80   virtual GBool useDrawChar() { return gFalse; }
81
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; }
85
86   //----- header/trailer (used only if manualCtrl is true)
87
88   // Write the document-level header.
89   void writeHeader(int firstPage, int lastPage, PDFRectangle *box);
90
91   // Write the Xpdf procset.
92   void writeXpdfProcset();
93
94   // Write the document-level setup.
95   void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
96
97   // Write the setup for the current page.
98   void writePageSetup();
99
100   // Write the trailer for the current page.
101   void writePageTrailer();
102
103   // Write the document trailer.
104   void writeTrailer();
105
106   //----- initialization and control
107
108   // Start a page.
109   virtual void startPage(int pageNum, GfxState *state);
110
111   // End a page.
112   virtual void endPage();
113
114   //----- save/restore graphics state
115   virtual void saveState(GfxState *state);
116   virtual void restoreState(GfxState *state);
117
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);
129
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);
140
141   //----- path painting
142   virtual void stroke(GfxState *state);
143   virtual void fill(GfxState *state);
144   virtual void eoFill(GfxState *state);
145
146   //----- path clipping
147   virtual void clip(GfxState *state);
148   virtual void eoClip(GfxState *state);
149
150   //----- text drawing
151   virtual void drawString(GfxState *state, GString *s);
152   virtual void endTextObject(GfxState *state);
153
154   //----- image drawing
155   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
156                              int width, int height, GBool invert,
157                              GBool inlineImg);
158   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
159                          int width, int height, GfxImageColorMap *colorMap,
160                          int *maskColors, GBool inlineImg);
161
162 #if OPI_SUPPORT
163   //----- OPI functions
164   virtual void opiBegin(GfxState *state, Dict *opiDict);
165   virtual void opiEnd(GfxState *state, Dict *opiDict);
166 #endif
167
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);
172
173   //----- PostScript XObjects
174   virtual void psXObject(Stream *psStream, Stream *level1Stream);
175
176   //----- miscellaneous
177   void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
178                       void *data)
179     { underlayCbk = cbk; underlayCbkData = data; }
180   void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
181                      void *data)
182     { overlayCbk = cbk; overlayCbkData = data; }
183
184 private:
185
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,
190             GBool manualCtrlA);
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);
217 #if OPI_SUPPORT
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);
223 #endif
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);
230
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
235
236   PSOutputFunc outputFunc;
237   void *outputStream;
238   PSFileType fileType;          // file / pipe / stdout
239   GBool manualCtrl;
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;
245
246   XRef *xref;                   // the xref table for this PDF file
247
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
258                                 //   font name
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
263                                 //   processed
264   int numSaves;                 // current number of gsaves
265
266   double tx, ty;                // global translation
267   double xScale, yScale;        // global scaling
268   GBool landscape;              // true for landscape, false for portrait
269
270   GString *embFontList;         // resource comments for embedded fonts
271
272   int processColors;            // used process colors
273   PSOutCustomColor              // used custom colors
274     *customColors;
275
276   GBool haveTextClip;           // set if text has been drawn with a
277                                 //   clipping render mode
278
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
284
285 #if OPI_SUPPORT
286   int opi13Nest;                // nesting level of OPI 1.3 objects
287   int opi20Nest;                // nesting level of OPI 2.0 objects
288 #endif
289
290   GBool ok;                     // set up ok?
291
292
293   friend class WinPDFPrinter;
294 };
295
296 #endif