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