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