added type3 char handling
[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 updateFontMatrix(GfxState *state);
100   virtual void updateFillColor(GfxState *state);
101   virtual void updateStrokeColor(GfxState *state);
102   virtual void updateLineWidth(GfxState *state);
103   virtual void updateLineJoin(GfxState *state);
104   virtual void updateLineCap(GfxState *state);
105   virtual void updateFillOpacity(GfxState *state);
106   virtual void updateStrokeOpacity(GfxState *state);
107   virtual void updateFillOverprint(GfxState *state);
108   virtual void updateStrokeOverprint(GfxState *state);
109   virtual void updateTransfer(GfxState *state);
110   
111   virtual void updateAll(GfxState *state) 
112   {
113       updateFont(state);
114       updateFillColor(state);
115       updateStrokeColor(state);
116       updateLineWidth(state);
117       updateLineJoin(state);
118       updateLineCap(state);
119   };
120
121   //----- path painting
122   virtual void stroke(GfxState *state) ;
123   virtual void fill(GfxState *state) ;
124   virtual void eoFill(GfxState *state) ;
125
126   //----- path clipping
127   virtual void clip(GfxState *state) ;
128   virtual void eoClip(GfxState *state) ;
129   virtual void clipToStrokePath(GfxState *state);
130  
131   //----- shaded fills
132   virtual GBool useTilingPatternFill();
133   virtual GBool useShadedFills();
134
135   /*
136   virtual void tilingPatternFill(GfxState *state, Object *str,
137                                  int paintType, Dict *resDict,
138                                  double *mat, double *bbox,
139                                  int x0, int y0, int x1, int y1,
140                                  double xStep, double yStep) {}
141   virtual void functionShadedFill(GfxState *state,
142                                   GfxFunctionShading *shading) {}
143   virtual void axialShadedFill(GfxState *state, GfxAxialShading *shading) {}
144   virtual void radialShadedFill(GfxState *state, GfxRadialShading *shading) {}
145   */
146
147   //----- text drawing
148   virtual void beginString(GfxState *state, GString *s) ;
149   virtual void endString(GfxState *state) ;
150   virtual void endTextObject(GfxState *state);
151   virtual void drawChar(GfxState *state, double x, double y,
152                         double dx, double dy,
153                         double originX, double originY,
154                         CharCode code, int nBytes, Unicode *u, int uLen);
155
156   //----- image drawing
157   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
158                              int width, int height, GBool invert,
159                              GBool inlineImg);
160   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
161                          int width, int height, GfxImageColorMap *colorMap,
162                          int *maskColors, GBool inlineImg);
163   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
164                                int width, int height,
165                                GfxImageColorMap *colorMap,
166                                Stream *maskStr, int maskWidth, int maskHeight,
167                                GBool maskInvert);
168   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
169                                    int width, int height,
170                                    GfxImageColorMap *colorMap,
171                                    Stream *maskStr,
172                                    int maskWidth, int maskHeight,
173                                    GfxImageColorMap *maskColorMap);
174
175   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
176   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
177                                       GfxColorSpace *blendingColorSpace,
178                                       GBool isolated, GBool knockout,
179                                       GBool forSoftMask);
180   virtual void endTransparencyGroup(GfxState *state);
181   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
182   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
183   virtual void clearSoftMask(GfxState *state);
184  
185   //----- type 3 chars
186   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
187   virtual void endType3Char(GfxState *state);
188
189   virtual void type3D0(GfxState *state, double wx, double wy);
190   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
191
192   void preparePage(int pdfpage, int outputpage);
193
194   char* searchForSuitableFont(GfxFont*gfxFont);
195
196   void finish();
197
198   virtual GBool useDrawForm();
199   virtual void drawForm(Ref id);
200   virtual GBool needNonText();
201   virtual void endPage();
202
203   //virtual void dump();
204   //virtual void beginStringOp(GfxState *state);
205   //virtual void drawString(GfxState *state, GString *s);
206   //virtual void endStringOp(GfxState *state);
207   //virtual GBool getVectorAntialias() { return gFalse; }
208   //virtual void setVectorAntialias(GBool vaa) {}
209   //virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
210
211   private:
212   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
213                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
214                                    GBool inlineImg, int mask, int *maskColors,
215                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
216   int setGfxFont(char*id, char*name, char*filename, double maxSize, CharCodeToUnicode*ctu);
217   void strokeGfxline(GfxState *state, gfxline_t*line, int flags);
218   void clipToGfxLine(GfxState *state, gfxline_t*line);
219   void fillGfxLine(GfxState *state, gfxline_t*line);
220
221   void showfeature(const char*feature,char fully, char warn);
222   void warnfeature(const char*feature,char fully);
223   void infofeature(const char*feature);
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   double width,height;
269
270   gfxline_t* current_text_stroke;
271   gfxline_t* current_text_clip;
272   char* current_font_id;
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
288   parameter_t*parameters;
289 };
290
291 class GFXGlobalParams:  public GlobalParams {
292     public:
293     GFXGlobalParams();
294     ~GFXGlobalParams();
295     virtual DisplayFontParam *getDisplayFont(GString *fontName);
296 };
297
298 #endif //__gfxoutputdev_h__