removed parameter_t
[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 _feature
35 {
36     char*string;
37     struct _feature*next;
38 } feature_t;
39
40 void addGlobalFont(const char*filename);
41 void addGlobalLanguageDir(const char*dir);
42 void addGlobalFontDir(const char*dirname);
43
44 class GFXOutputDev:  public CommonOutputDev {
45 public:
46   gfxdevice_t* device;
47
48   GFXOutputDev(InfoOutputDev*info, PDFDoc*doc);
49   virtual ~GFXOutputDev() ;
50
51   virtual void setDevice(gfxdevice_t*dev);
52   virtual void setMove(int x,int y);
53   virtual void setClip(int x1,int y1,int x2,int y2);
54   virtual void setParameter(const char*key, const char*value);
55   
56   // Start a page.
57   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
58   virtual void endPage();
59
60   //----- get info about output device
61
62   // Does this device use upside-down coordinates?
63   // (Upside-down means (0,0) is the top left corner of the page.)
64   virtual GBool upsideDown();
65
66   // Does this device use drawChar() or drawString()?
67   virtual GBool useDrawChar();
68   
69   virtual GBool interpretType3Chars();
70   
71   //virtual GBool useShadedFills() { return gTrue; }
72
73   //----- link borders
74   virtual void processLink(Link *link, Catalog *catalog);
75
76   //----- save/restore graphics state
77   virtual void saveState(GfxState *state) ;
78   virtual void restoreState(GfxState *state) ;
79
80   //----- update graphics state
81
82   virtual void updateLineDash(GfxState *state);
83   virtual void updateFont(GfxState *state);
84   virtual void updateFontMatrix(GfxState *state);
85   virtual void updateFillColor(GfxState *state);
86   virtual void updateStrokeColor(GfxState *state);
87   virtual void updateLineWidth(GfxState *state);
88   virtual void updateLineJoin(GfxState *state);
89   virtual void updateLineCap(GfxState *state);
90   virtual void updateFillOpacity(GfxState *state);
91   virtual void updateStrokeOpacity(GfxState *state);
92   virtual void updateFillOverprint(GfxState *state);
93   virtual void updateStrokeOverprint(GfxState *state);
94   virtual void updateTransfer(GfxState *state);
95   
96   virtual void updateAll(GfxState *state) 
97   {
98       updateFont(state);
99       updateFillColor(state);
100       updateStrokeColor(state);
101       updateLineWidth(state);
102       updateLineJoin(state);
103       updateLineCap(state);
104   };
105
106   //----- path painting
107   virtual void stroke(GfxState *state) ;
108   virtual void fill(GfxState *state) ;
109   virtual void eoFill(GfxState *state) ;
110
111   //----- path clipping
112   virtual void clip(GfxState *state) ;
113   virtual void eoClip(GfxState *state) ;
114   virtual void clipToStrokePath(GfxState *state);
115  
116   //----- shaded fills
117   virtual GBool useTilingPatternFill();
118   virtual GBool useShadedFills();
119
120 #if (xpdfMajorVersion < 3) || (xpdfMinorVersion < 2) || (xpdfUpdateVersion < 7)
121   virtual void tilingPatternFill(GfxState *state, Object *str,
122                              int paintType, Dict *resDict,
123                              double *mat, double *bbox,
124                              int x0, int y0, int x1, int y1,
125                              double xStep, double yStep);
126 #else
127   virtual void tilingPatternFill(GfxState *state, Gfx *gfx, 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 #endif
133   virtual GBool functionShadedFill(GfxState *state,
134                                    GfxFunctionShading *shading);
135   virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
136   virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
137
138   //----- text drawing
139   virtual void beginString(GfxState *state, GString *s) ;
140   virtual void endString(GfxState *state) ;
141   virtual void endTextObject(GfxState *state);
142   virtual void drawChar(GfxState *state, double x, double y,
143                         double dx, double dy,
144                         double originX, double originY,
145                         CharCode code, int nBytes, Unicode *u, int uLen);
146
147   //----- image drawing
148   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
149                              int width, int height, GBool invert,
150                              GBool inlineImg);
151   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
152                          int width, int height, GfxImageColorMap *colorMap,
153                          int *maskColors, GBool inlineImg);
154   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
155                                int width, int height,
156                                GfxImageColorMap *colorMap,
157                                Stream *maskStr, int maskWidth, int maskHeight,
158                                GBool maskInvert);
159   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
160                                    int width, int height,
161                                    GfxImageColorMap *colorMap,
162                                    Stream *maskStr,
163                                    int maskWidth, int maskHeight,
164                                    GfxImageColorMap *maskColorMap);
165
166   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
167   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
168                                       GfxColorSpace *blendingColorSpace,
169                                       GBool isolated, GBool knockout,
170                                       GBool forSoftMask);
171   virtual void endTransparencyGroup(GfxState *state);
172   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
173   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
174   virtual void clearSoftMask(GfxState *state);
175  
176   //----- type 3 chars
177   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
178   virtual void endType3Char(GfxState *state);
179
180   virtual void type3D0(GfxState *state, double wx, double wy);
181   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
182
183   virtual void preparePage(int pdfpage, int outputpage);
184
185   char* searchForSuitableFont(GfxFont*gfxFont);
186
187   void finish();
188
189   virtual GBool useDrawForm();
190   virtual void drawForm(Ref id);
191   virtual GBool needNonText();
192
193   //virtual void dump();
194   //virtual void beginStringOp(GfxState *state);
195   //virtual void drawString(GfxState *state, GString *s);
196   //virtual void endStringOp(GfxState *state);
197   //virtual GBool getVectorAntialias() { return gFalse; }
198   //virtual void setVectorAntialias(GBool vaa) {}
199   //virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
200
201   private:
202   gfxline_t* gfxPath_to_gfxline(GfxState*state, GfxPath*path, int closed, int user_movex, int user_movey);
203
204   void transformXY(GfxState*state, double x, double y, double*nx, double*ny);
205
206   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
207                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
208                                    GBool inlineImg, int mask, int *maskColors,
209                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
210   int setGfxFont(char*id, char*name, char*filename, double maxSize, CharCodeToUnicode*ctu);
211   void strokeGfxline(GfxState *state, gfxline_t*line, int flags);
212   void clipToGfxLine(GfxState *state, gfxline_t*line);
213   void fillGfxLine(GfxState *state, gfxline_t*line);
214
215   void showfeature(const char*feature,char fully, char warn);
216   void warnfeature(const char*feature,char fully);
217   void infofeature(const char*feature);
218
219   feature_t*featurewarnings;
220
221   char outer_clip_box; //whether the page clip box is still on
222
223   gfxfontlist_t*gfxfontlist;
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   gfxline_t* current_text_stroke;
265   gfxline_t* current_text_clip;
266   gfxfont_t* current_gfxfont;
267   FontInfo*current_fontinfo;
268   gfxmatrix_t current_font_matrix;
269
270   int*pages;
271   int pagebuflen;
272   int pagepos;
273
274   /* config */
275   int config_use_fontconfig;
276   int config_break_on_warning;
277   int config_remapunicode;
278   int config_transparent;
279   int config_extrafontdata;
280   int config_convertgradients;
281   int config_optimize_polygons;
282   double config_fontquality;
283     
284   double *dashPattern;
285   int dashLength;
286   double dashStart;
287 };
288
289 class GFXGlobalParams:  public GlobalParams {
290     public:
291     GFXGlobalParams();
292     ~GFXGlobalParams();
293     virtual DisplayFontParam *getDisplayFont(GString *fontName);
294 };
295
296 #endif //__gfxoutputdev_h__