added softmask/tgroup fields
[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   //----- text drawing
125   virtual void beginString(GfxState *state, GString *s) ;
126   virtual void endString(GfxState *state) ;
127   virtual void endTextObject(GfxState *state);
128   virtual void drawChar(GfxState *state, double x, double y,
129                         double dx, double dy,
130                         double originX, double originY,
131                         CharCode code, int nBytes, Unicode *u, int uLen);
132
133   //----- image drawing
134   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
135                              int width, int height, GBool invert,
136                              GBool inlineImg);
137   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
138                          int width, int height, GfxImageColorMap *colorMap,
139                          int *maskColors, GBool inlineImg);
140   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
141                                int width, int height,
142                                GfxImageColorMap *colorMap,
143                                Stream *maskStr, int maskWidth, int maskHeight,
144                                GBool maskInvert);
145   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
146                                    int width, int height,
147                                    GfxImageColorMap *colorMap,
148                                    Stream *maskStr,
149                                    int maskWidth, int maskHeight,
150                                    GfxImageColorMap *maskColorMap);
151
152   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
153 #if xpdfUpdateVersion >= 16
154   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
155                                       GfxColorSpace *blendingColorSpace,
156                                       GBool isolated, GBool knockout,
157                                       GBool forSoftMask);
158   virtual void endTransparencyGroup(GfxState *state);
159   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
160   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
161   virtual void clearSoftMask(GfxState *state);
162 #endif
163  
164   //----- type 3 chars
165   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
166   virtual void endType3Char(GfxState *state);
167
168   virtual void type3D0(GfxState *state, double wx, double wy);
169   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
170
171   void preparePage(int pdfpage, int outputpage);
172
173   char* searchForSuitableFont(GfxFont*gfxFont);
174
175   void finish();
176
177   private:
178   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
179                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
180                                    GBool inlineImg, int mask, int *maskColors,
181                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
182   int setGfxFont(char*id, char*name, char*filename, double quality);
183   void strokeGfxline(GfxState *state, gfxline_t*line);
184   void clipToGfxLine(GfxState *state, gfxline_t*line);
185   void fillGfxLine(GfxState *state, gfxline_t*line);
186
187   char outer_clip_box; //whether the page clip box is still on
188
189   InfoOutputDev*info;
190   GFXOutputState states[64];
191   int statepos;
192
193   int currentpage;
194
195   PDFDoc*doc;
196   XRef*xref;
197
198   char* searchFont(char*name);
199   char* substituteFont(GfxFont*gfxFont, char*oldname);
200   char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
201   int t1id;
202   int textmodeinfo; // did we write "Text will be rendered as polygon" yet?
203   int jpeginfo; // did we write "File contains jpegs" yet?
204   int pbminfo; // did we write "File contains jpegs" yet?
205   int linkinfo; // did we write "File contains links" yet?
206   int ttfinfo; // did we write "File contains TrueType Fonts" yet?
207   int gradientinfo; // did we write "File contains Gradients yet?
208
209   int type3active; // are we between beginType3()/endType3()?
210
211   GfxState *laststate;
212
213   char type3Warning;
214
215   char* substitutetarget[256];
216   char* substitutesource[256];
217   int substitutepos;
218
219   int user_movex,user_movey;
220   int user_clipx1,user_clipx2,user_clipy1,user_clipy2;
221
222   /* upper left corner of clipping rectangle (cropbox)- needs to be
223      added to all drawing coordinates to give the impression that all
224      pages start at (0,0)*/
225   int clipmovex;
226   int clipmovey;
227
228   double width,height;
229
230   gfxline_t* current_text_stroke;
231   gfxline_t* current_text_clip;
232   char* current_font_id;
233   gfxfont_t* current_gfxfont;
234   gfxmatrix_t current_font_matrix;
235
236   fontlist_t* fontlist;
237
238   int*pages;
239   int pagebuflen;
240   int pagepos;
241
242   /* config */
243   int forceType0Fonts;
244   int config_use_fontconfig;
245
246   parameter_t*parameters;
247 };
248
249 #endif //__gfxoutputdev_h__