]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/PSOutputDev.h
6c379a9c51a6624e9ef51b4b71c8e0d44a7aeaaa
[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 imgLLXA = 0, int imgLLYA = 0,
58               int imgURXA = 0, int imgURYA = 0,
59               GBool manualCtrlA = gFalse);
60
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);
68
69   // Destructor -- writes the trailer and closes the file.
70   virtual ~PSOutputDev();
71
72   // Check if file was successfully created.
73   virtual GBool isOk() { return ok; }
74
75   //---- get info about output device
76
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; }
80
81   // Does this device use drawChar() or drawString()?
82   virtual GBool useDrawChar() { return gFalse; }
83
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; }
87
88   //----- header/trailer (used only if manualCtrl is true)
89
90   // Write the document-level header.
91   void writeHeader(int firstPage, int lastPage,
92                    PDFRectangle *mediaBox, PDFRectangle *cropBox);
93
94   // Write the Xpdf procset.
95   void writeXpdfProcset();
96
97   // Write the document-level setup.
98   void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
99
100   // Write the setup for the current page.
101   void writePageSetup();
102
103   // Write the trailer for the current page.
104   void writePageTrailer();
105
106   // Write the document trailer.
107   void writeTrailer();
108
109   //----- initialization and control
110
111   // Start a page.
112   virtual void startPage(int pageNum, GfxState *state);
113
114   // End a page.
115   virtual void endPage();
116
117   //----- save/restore graphics state
118   virtual void saveState(GfxState *state);
119   virtual void restoreState(GfxState *state);
120
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);
132
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);
143
144   //----- path painting
145   virtual void stroke(GfxState *state);
146   virtual void fill(GfxState *state);
147   virtual void eoFill(GfxState *state);
148
149   //----- path clipping
150   virtual void clip(GfxState *state);
151   virtual void eoClip(GfxState *state);
152
153   //----- text drawing
154   virtual void drawString(GfxState *state, GString *s);
155   virtual void endTextObject(GfxState *state);
156
157   //----- image drawing
158   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
159                              int width, int height, GBool invert,
160                              GBool inlineImg);
161   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
162                          int width, int height, GfxImageColorMap *colorMap,
163                          int *maskColors, GBool inlineImg);
164
165 #if OPI_SUPPORT
166   //----- OPI functions
167   virtual void opiBegin(GfxState *state, Dict *opiDict);
168   virtual void opiEnd(GfxState *state, Dict *opiDict);
169 #endif
170
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);
175
176   //----- PostScript XObjects
177   virtual void psXObject(Stream *psStream, Stream *level1Stream);
178
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),
189                       void *data)
190     { underlayCbk = cbk; underlayCbkData = data; }
191   void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
192                      void *data)
193     { overlayCbk = cbk; overlayCbkData = data; }
194
195 private:
196
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,
201             GBool manualCtrlA);
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);
228 #if OPI_SUPPORT
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);
234 #endif
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);
241
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
247       imgURX, imgURY;
248
249   PSOutputFunc outputFunc;
250   void *outputStream;
251   PSFileType fileType;          // file / pipe / stdout
252   GBool manualCtrl;
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;
258
259   XRef *xref;                   // the xref table for this PDF file
260
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
271                                 //   font name
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
276                                 //   processed
277   int numSaves;                 // current number of gsaves
278
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,
283          clipURX0, clipURY0;
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
287
288   GString *embFontList;         // resource comments for embedded fonts
289
290   int processColors;            // used process colors
291   PSOutCustomColor              // used custom colors
292     *customColors;
293
294   GBool haveTextClip;           // set if text has been drawn with a
295                                 //   clipping render mode
296
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
302
303 #if OPI_SUPPORT
304   int opi13Nest;                // nesting level of OPI 1.3 objects
305   int opi20Nest;                // nesting level of OPI 2.0 objects
306 #endif
307
308   GBool ok;                     // set up ok?
309
310
311   friend class WinPDFPrinter;
312 };
313
314 #endif