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