implemented a few more OutputDev functions
[swftools.git] / lib / pdf / GFXOutputDev.h
1 #ifndef __gfxoutputdev_h__
2 #define __gfxoutputdev_h__
3
4 #include "../gfxdevice.h"
5 #include "../gfxsource.h"
6
7 #include "config.h"
8 #include "InfoOutputDev.h"
9 #include "PDFDoc.h"
10
11 typedef struct _fontlist
12 {
13     char*filename;
14     gfxfont_t*font;
15     _fontlist*next;
16 } fontlist_t;
17
18 class GFXOutputState {
19     public:
20     int clipping;
21     int textRender;
22     char createsoftmask;
23     char transparencygroup;
24     char softmask;
25     char softmask_alpha;
26     char isolated;
27
28     GFXOutputState();
29
30     gfxresult_t* grouprecording; // for transparency groups
31     gfxresult_t* softmaskrecording; // for soft masks
32
33     gfxdevice_t* olddevice;
34 };
35
36 typedef struct _parameter
37 {
38     char*name;
39     char*value;
40     struct _parameter*next;
41 } parameter_t;
42
43 void addGlobalFont(const char*filename);
44 void addGlobalLanguageDir(const char*dir);
45 void addGlobalFontDir(const char*dirname);
46
47 class GFXOutputDev:  public OutputDev {
48 public:
49   gfxdevice_t* device;
50
51   // Constructor.
52   GFXOutputDev(parameter_t*p);
53   void setDevice(gfxdevice_t*dev);
54
55   // Destructor.
56   virtual ~GFXOutputDev() ;
57
58   void setMove(int x,int y);
59   void setClip(int x1,int y1,int x2,int y2);
60   void setParameter(const char*key, const char*value);
61
62   void setInfo(InfoOutputDev*info) {this->info = info;}
63   
64   // Start a page.
65   void startFrame(int width, int height);
66
67   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
68
69   void endframe();
70
71   //----- get info about output device
72
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();
76
77   // Does this device use drawChar() or drawString()?
78   virtual GBool useDrawChar();
79   
80   virtual GBool interpretType3Chars();
81   
82   //virtual GBool useShadedFills() { return gTrue; }
83
84   //----- initialization and control
85
86   void setXRef(PDFDoc*doc, XRef *xref);
87
88   //----- link borders
89   virtual void processLink(Link *link, Catalog *catalog);
90
91   //----- save/restore graphics state
92   virtual void saveState(GfxState *state) ;
93   virtual void restoreState(GfxState *state) ;
94
95   //----- update graphics state
96
97   virtual void updateFont(GfxState *state);
98   virtual void updateFillColor(GfxState *state);
99   virtual void updateStrokeColor(GfxState *state);
100   virtual void updateLineWidth(GfxState *state);
101   virtual void updateLineJoin(GfxState *state);
102   virtual void updateLineCap(GfxState *state);
103   virtual void updateFillOpacity(GfxState *state);
104   virtual void updateStrokeOpacity(GfxState *state);
105   virtual void updateFillOverprint(GfxState *state);
106   virtual void updateStrokeOverprint(GfxState *state);
107   virtual void updateTransfer(GfxState *state);
108   
109   virtual void updateAll(GfxState *state) 
110   {
111       updateFont(state);
112       updateFillColor(state);
113       updateStrokeColor(state);
114       updateLineWidth(state);
115       updateLineJoin(state);
116       updateLineCap(state);
117   };
118
119   //----- path painting
120   virtual void stroke(GfxState *state) ;
121   virtual void fill(GfxState *state) ;
122   virtual void eoFill(GfxState *state) ;
123
124   //----- path clipping
125   virtual void clip(GfxState *state) ;
126   virtual void eoClip(GfxState *state) ;
127   virtual void clipToStrokePath(GfxState *state);
128  
129   //----- shaded fills
130   virtual GBool useTilingPatternFill();
131   virtual GBool useShadedFills();
132
133   /*
134   virtual void tilingPatternFill(GfxState *state, Object *str,
135                                  int paintType, Dict *resDict,
136                                  double *mat, double *bbox,
137                                  int x0, int y0, int x1, int y1,
138                                  double xStep, double yStep) {}
139   virtual void functionShadedFill(GfxState *state,
140                                   GfxFunctionShading *shading) {}
141   virtual void axialShadedFill(GfxState *state, GfxAxialShading *shading) {}
142   virtual void radialShadedFill(GfxState *state, GfxRadialShading *shading) {}
143   */
144
145   //----- text drawing
146   virtual void beginString(GfxState *state, GString *s) ;
147   virtual void endString(GfxState *state) ;
148   virtual void endTextObject(GfxState *state);
149   virtual void drawChar(GfxState *state, double x, double y,
150                         double dx, double dy,
151                         double originX, double originY,
152                         CharCode code, int nBytes, Unicode *u, int uLen);
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   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
162                                int width, int height,
163                                GfxImageColorMap *colorMap,
164                                Stream *maskStr, int maskWidth, int maskHeight,
165                                GBool maskInvert);
166   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
167                                    int width, int height,
168                                    GfxImageColorMap *colorMap,
169                                    Stream *maskStr,
170                                    int maskWidth, int maskHeight,
171                                    GfxImageColorMap *maskColorMap);
172
173   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
174   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
175                                       GfxColorSpace *blendingColorSpace,
176                                       GBool isolated, GBool knockout,
177                                       GBool forSoftMask);
178   virtual void endTransparencyGroup(GfxState *state);
179   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
180   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
181   virtual void clearSoftMask(GfxState *state);
182  
183   //----- type 3 chars
184   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
185   virtual void endType3Char(GfxState *state);
186
187   virtual void type3D0(GfxState *state, double wx, double wy);
188   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
189
190   void preparePage(int pdfpage, int outputpage);
191
192   char* searchForSuitableFont(GfxFont*gfxFont);
193
194   void finish();
195
196   virtual GBool useDrawForm();
197   virtual void drawForm(Ref id);
198   virtual GBool needNonText();
199   virtual void endPage();
200
201   //virtual void dump();
202   //virtual void beginStringOp(GfxState *state);
203   //virtual void drawString(GfxState *state, GString *s);
204   //virtual void endStringOp(GfxState *state);
205   //virtual GBool getVectorAntialias() { return gFalse; }
206   //virtual void setVectorAntialias(GBool vaa) {}
207   //virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
208
209   private:
210   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
211                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
212                                    GBool inlineImg, int mask, int *maskColors,
213                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
214   int setGfxFont(char*id, char*name, char*filename, double quality);
215   void strokeGfxline(GfxState *state, gfxline_t*line, int flags);
216   void clipToGfxLine(GfxState *state, gfxline_t*line);
217   void fillGfxLine(GfxState *state, gfxline_t*line);
218
219   void showfeature(const char*feature,char fully, char warn);
220   void warnfeature(const char*feature,char fully);
221   void infofeature(const char*feature);
222
223   char outer_clip_box; //whether the page clip box is still on
224   
225   GBool do_interpretType3Chars;
226
227   InfoOutputDev*info;
228   GFXOutputState states[64];
229   int statepos;
230
231   int currentpage;
232
233   PDFDoc*doc;
234   XRef*xref;
235
236   char* searchFont(const char*name);
237   char* substituteFont(GfxFont*gfxFont, char*oldname);
238   char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
239   int t1id;
240   int textmodeinfo; // did we write "Text will be rendered as polygon" yet?
241   int jpeginfo; // did we write "File contains jpegs" yet?
242   int pbminfo; // did we write "File contains jpegs" yet?
243   int linkinfo; // did we write "File contains links" yet?
244
245   int type3active; // are we between beginType3()/endType3()?
246
247   GfxState *laststate;
248
249   char type3Warning;
250
251   const char* substitutetarget[256];
252   const char* substitutesource[256];
253   int substitutepos;
254
255   int user_movex,user_movey;
256   int user_clipx1,user_clipx2,user_clipy1,user_clipy2;
257
258   /* upper left corner of clipping rectangle (cropbox)- needs to be
259      added to all drawing coordinates to give the impression that all
260      pages start at (0,0)*/
261   int clipmovex;
262   int clipmovey;
263
264   double width,height;
265
266   gfxline_t* current_text_stroke;
267   gfxline_t* current_text_clip;
268   char* current_font_id;
269   gfxfont_t* current_gfxfont;
270   gfxmatrix_t current_font_matrix;
271
272   fontlist_t* fontlist;
273
274   int*pages;
275   int pagebuflen;
276   int pagepos;
277
278   /* config */
279   int config_use_fontconfig;
280   int config_break_on_warning;
281
282   parameter_t*parameters;
283 };
284
285 #endif //__gfxoutputdev_h__