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