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