89c6185db671f35d5ec5ed146e852de2a6e3da00
[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 void addGlobalFont(const char*filename);
42 void addGlobalLanguageDir(const char*dir);
43 void addGlobalFontDir(const char*dirname);
44
45 class GFXOutputDev:  public CommonOutputDev {
46 public:
47   gfxdevice_t* device;
48
49   GFXOutputDev(InfoOutputDev*info, PDFDoc*doc);
50   virtual ~GFXOutputDev() ;
51
52   virtual void setDevice(gfxdevice_t*dev);
53   virtual void setMove(int x,int y);
54   virtual void setClip(int x1,int y1,int x2,int y2);
55   virtual void setParameter(const char*key, const char*value);
56   
57   // Start a page.
58   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
59   virtual void endPage();
60
61   //----- get info about output device
62
63   // Does this device use upside-down coordinates?
64   // (Upside-down means (0,0) is the top left corner of the page.)
65   virtual GBool upsideDown();
66
67   // Does this device use drawChar() or drawString()?
68   virtual GBool useDrawChar();
69   
70   virtual GBool interpretType3Chars();
71   
72   //virtual GBool useShadedFills() { return gTrue; }
73
74   //----- link borders
75   virtual void processLink(Link *link, Catalog *catalog);
76
77   //----- save/restore graphics state
78   virtual void saveState(GfxState *state) ;
79   virtual void restoreState(GfxState *state) ;
80
81   //----- update graphics state
82
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   char outer_clip_box; //whether the page clip box is still on
220
221   gfxfontlist_t*gfxfontlist;
222
223   GBool do_interpretType3Chars;
224
225   InfoOutputDev*info;
226   GFXOutputState states[64];
227   int statepos;
228
229   int currentpage;
230
231   PDFDoc*doc;
232   XRef*xref;
233
234   char* searchFont(const char*name);
235   char* substituteFont(GfxFont*gfxFont, char*oldname);
236   char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
237   int t1id;
238   int textmodeinfo; // did we write "Text will be rendered as polygon" yet?
239   int jpeginfo; // did we write "File contains jpegs" yet?
240   int pbminfo; // did we write "File contains jpegs" yet?
241   int linkinfo; // did we write "File contains links" yet?
242
243   int type3active; // are we between beginType3()/endType3()?
244
245   GfxState *laststate;
246
247   char type3Warning;
248
249   const char* substitutetarget[256];
250   const char* substitutesource[256];
251   int substitutepos;
252
253   int user_movex,user_movey;
254   int user_clipx1,user_clipx2,user_clipy1,user_clipy2;
255
256   /* upper left corner of clipping rectangle (cropbox)- needs to be
257      added to all drawing coordinates to give the impression that all
258      pages start at (0,0)*/
259   int clipmovex;
260   int clipmovey;
261
262   gfxline_t* current_text_stroke;
263   gfxline_t* current_text_clip;
264   gfxfont_t* current_gfxfont;
265   FontInfo*current_fontinfo;
266   gfxmatrix_t current_font_matrix;
267
268   int*pages;
269   int pagebuflen;
270   int pagepos;
271
272   /* config */
273   int config_use_fontconfig;
274   int config_break_on_warning;
275   int config_remapunicode;
276   int config_transparent;
277   int config_extrafontdata;
278   int config_convertgradients;
279   int config_optimize_polygons;
280   double config_fontquality;
281
282   parameter_t*parameters;
283 };
284
285 class GFXGlobalParams:  public GlobalParams {
286     public:
287     GFXGlobalParams();
288     ~GFXGlobalParams();
289     virtual DisplayFontParam *getDisplayFont(GString *fontName);
290 };
291
292 #endif //__gfxoutputdev_h__