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