added updateLineDash implementation
[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 updateLineDash(GfxState *state);
90   virtual void updateFont(GfxState *state);
91   virtual void updateFontMatrix(GfxState *state);
92   virtual void updateFillColor(GfxState *state);
93   virtual void updateStrokeColor(GfxState *state);
94   virtual void updateLineWidth(GfxState *state);
95   virtual void updateLineJoin(GfxState *state);
96   virtual void updateLineCap(GfxState *state);
97   virtual void updateFillOpacity(GfxState *state);
98   virtual void updateStrokeOpacity(GfxState *state);
99   virtual void updateFillOverprint(GfxState *state);
100   virtual void updateStrokeOverprint(GfxState *state);
101   virtual void updateTransfer(GfxState *state);
102   
103   virtual void updateAll(GfxState *state) 
104   {
105       updateFont(state);
106       updateFillColor(state);
107       updateStrokeColor(state);
108       updateLineWidth(state);
109       updateLineJoin(state);
110       updateLineCap(state);
111   };
112
113   //----- path painting
114   virtual void stroke(GfxState *state) ;
115   virtual void fill(GfxState *state) ;
116   virtual void eoFill(GfxState *state) ;
117
118   //----- path clipping
119   virtual void clip(GfxState *state) ;
120   virtual void eoClip(GfxState *state) ;
121   virtual void clipToStrokePath(GfxState *state);
122  
123   //----- shaded fills
124   virtual GBool useTilingPatternFill();
125   virtual GBool useShadedFills();
126
127 #if (xpdfMajorVersion < 3) || (xpdfMinorVersion < 2) || (xpdfUpdateVersion < 7)
128   virtual void tilingPatternFill(GfxState *state, Object *str,
129                              int paintType, Dict *resDict,
130                              double *mat, double *bbox,
131                              int x0, int y0, int x1, int y1,
132                              double xStep, double yStep);
133 #else
134   virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
135                              int paintType, Dict *resDict,
136                              double *mat, double *bbox,
137                              int x0, int y0, int x1, int y1,
138                              double xStep, double yStep);
139 #endif
140   virtual GBool functionShadedFill(GfxState *state,
141                                    GfxFunctionShading *shading);
142   virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
143   virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
144
145   //----- text drawing
146   virtual void beginString(GfxState *state, GString *s) ;
147   virtual void endString(GfxState *state) ;
148   virtual void endTextObject(GfxState *state);
149   virtual void drawChar(GfxState *state, double x, double y,
150                         double dx, double dy,
151                         double originX, double originY,
152                         CharCode code, int nBytes, Unicode *u, int uLen);
153
154   //----- image drawing
155   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
156                              int width, int height, GBool invert,
157                              GBool inlineImg);
158   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
159                          int width, int height, GfxImageColorMap *colorMap,
160                          int *maskColors, GBool inlineImg);
161   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
162                                int width, int height,
163                                GfxImageColorMap *colorMap,
164                                Stream *maskStr, int maskWidth, int maskHeight,
165                                GBool maskInvert);
166   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
167                                    int width, int height,
168                                    GfxImageColorMap *colorMap,
169                                    Stream *maskStr,
170                                    int maskWidth, int maskHeight,
171                                    GfxImageColorMap *maskColorMap);
172
173   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
174   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
175                                       GfxColorSpace *blendingColorSpace,
176                                       GBool isolated, GBool knockout,
177                                       GBool forSoftMask);
178   virtual void endTransparencyGroup(GfxState *state);
179   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
180   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
181   virtual void clearSoftMask(GfxState *state);
182  
183   //----- type 3 chars
184   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
185   virtual void endType3Char(GfxState *state);
186
187   virtual void type3D0(GfxState *state, double wx, double wy);
188   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
189
190   virtual void preparePage(int pdfpage, int outputpage);
191
192   char* searchForSuitableFont(GfxFont*gfxFont);
193
194   void finish();
195
196   virtual GBool useDrawForm();
197   virtual void drawForm(Ref id);
198   virtual GBool needNonText();
199
200   //virtual void dump();
201   //virtual void beginStringOp(GfxState *state);
202   //virtual void drawString(GfxState *state, GString *s);
203   //virtual void endStringOp(GfxState *state);
204   //virtual GBool getVectorAntialias() { return gFalse; }
205   //virtual void setVectorAntialias(GBool vaa) {}
206   //virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
207
208   private:
209   gfxline_t* gfxPath_to_gfxline(GfxState*state, GfxPath*path, int closed, int user_movex, int user_movey);
210
211   void transformXY(GfxState*state, double x, double y, double*nx, double*ny);
212
213   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
214                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
215                                    GBool inlineImg, int mask, int *maskColors,
216                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
217   int setGfxFont(char*id, char*name, char*filename, double maxSize, CharCodeToUnicode*ctu);
218   void strokeGfxline(GfxState *state, gfxline_t*line, int flags);
219   void clipToGfxLine(GfxState *state, gfxline_t*line);
220   void fillGfxLine(GfxState *state, gfxline_t*line);
221
222   void showfeature(const char*feature,char fully, char warn);
223   void warnfeature(const char*feature,char fully);
224   void infofeature(const char*feature);
225
226   feature_t*featurewarnings;
227
228   char outer_clip_box; //whether the page clip box is still on
229
230   gfxfontlist_t*gfxfontlist;
231
232   GBool do_interpretType3Chars;
233
234   InfoOutputDev*info;
235   GFXOutputState states[64];
236   int statepos;
237
238   int currentpage;
239
240   PDFDoc*doc;
241   XRef*xref;
242
243   char* searchFont(const char*name);
244   char* substituteFont(GfxFont*gfxFont, char*oldname);
245   char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
246   int t1id;
247   int textmodeinfo; // did we write "Text will be rendered as polygon" yet?
248   int jpeginfo; // did we write "File contains jpegs" yet?
249   int pbminfo; // did we write "File contains jpegs" yet?
250   int linkinfo; // did we write "File contains links" yet?
251
252   int type3active; // are we between beginType3()/endType3()?
253
254   GfxState *laststate;
255
256   char type3Warning;
257
258   const char* substitutetarget[256];
259   const char* substitutesource[256];
260   int substitutepos;
261
262   int user_movex,user_movey;
263   int user_clipx1,user_clipx2,user_clipy1,user_clipy2;
264
265   /* upper left corner of clipping rectangle (cropbox)- needs to be
266      added to all drawing coordinates to give the impression that all
267      pages start at (0,0)*/
268   int clipmovex;
269   int clipmovey;
270
271   gfxline_t* current_text_stroke;
272   gfxline_t* current_text_clip;
273   gfxfont_t* current_gfxfont;
274   FontInfo*current_fontinfo;
275   gfxmatrix_t current_font_matrix;
276
277   int*pages;
278   int pagebuflen;
279   int pagepos;
280
281   /* config */
282   int config_use_fontconfig;
283   int config_break_on_warning;
284   int config_remapunicode;
285   int config_transparent;
286   int config_extrafontdata;
287   int config_convertgradients;
288   int config_optimize_polygons;
289   double config_fontquality;
290     
291   double *dashPattern;
292   int dashLength;
293   double dashStart;
294
295   parameter_t*parameters;
296 };
297
298 class GFXGlobalParams:  public GlobalParams {
299     public:
300     GFXGlobalParams();
301     ~GFXGlobalParams();
302     virtual DisplayFontParam *getDisplayFont(GString *fontName);
303 };
304
305 #endif //__gfxoutputdev_h__