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