transparencygroup/softmask workarounds
[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     GFXOutputState();
24 };
25
26 typedef struct _parameter
27 {
28     char*name;
29     char*value;
30     struct _parameter*next;
31 } parameter_t;
32
33 void addGlobalFont(char*filename);
34 void addGlobalLanguageDir(char*dir);
35 void addGlobalFontDir(char*dirname);
36
37 class GFXOutputDev:  public OutputDev {
38 public:
39   gfxdevice_t* device;
40
41   // Constructor.
42   GFXOutputDev(parameter_t*p);
43   void setDevice(gfxdevice_t*dev);
44
45   // Destructor.
46   virtual ~GFXOutputDev() ;
47
48   void setMove(int x,int y);
49   void setClip(int x1,int y1,int x2,int y2);
50
51   void setInfo(InfoOutputDev*info) {this->info = info;}
52   
53   // Start a page.
54   void startFrame(int width, int height);
55
56   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
57
58   void endframe();
59
60   //----- get info about output device
61
62   // Does this device use upside-down coordinates?
63   // (Upside-down means (0,0) is the top left corner of the page.)
64   virtual GBool upsideDown();
65
66   // Does this device use drawChar() or drawString()?
67   virtual GBool useDrawChar();
68   
69   virtual GBool interpretType3Chars();
70   
71   //virtual GBool useShadedFills() { return gTrue; }
72
73   //----- initialization and control
74
75   void setXRef(PDFDoc*doc, XRef *xref);
76
77   //----- link borders
78   virtual void drawLink(Link *link, Catalog *catalog) ;
79
80   //----- save/restore graphics state
81   virtual void saveState(GfxState *state) ;
82   virtual void restoreState(GfxState *state) ;
83
84   //----- update graphics state
85
86   virtual void updateFont(GfxState *state);
87   virtual void updateFillColor(GfxState *state);
88   virtual void updateStrokeColor(GfxState *state);
89   virtual void updateLineWidth(GfxState *state);
90   virtual void updateLineJoin(GfxState *state);
91   virtual void updateLineCap(GfxState *state);
92   virtual void updateFillOpacity(GfxState *state);
93
94   
95   virtual void updateAll(GfxState *state) 
96   {
97       updateFont(state);
98       updateFillColor(state);
99       updateStrokeColor(state);
100       updateLineWidth(state);
101       updateLineJoin(state);
102       updateLineCap(state);
103   };
104
105   //----- path painting
106   virtual void stroke(GfxState *state) ;
107   virtual void fill(GfxState *state) ;
108   virtual void eoFill(GfxState *state) ;
109
110   //----- path clipping
111   virtual void clip(GfxState *state) ;
112   virtual void eoClip(GfxState *state) ;
113
114   //----- text drawing
115   virtual void beginString(GfxState *state, GString *s) ;
116   virtual void endString(GfxState *state) ;
117   virtual void endTextObject(GfxState *state);
118   virtual void drawChar(GfxState *state, double x, double y,
119                         double dx, double dy,
120                         double originX, double originY,
121                         CharCode code, int nBytes, Unicode *u, int uLen);
122
123   //----- image drawing
124   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
125                              int width, int height, GBool invert,
126                              GBool inlineImg);
127   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
128                          int width, int height, GfxImageColorMap *colorMap,
129                          int *maskColors, GBool inlineImg);
130   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
131                                int width, int height,
132                                GfxImageColorMap *colorMap,
133                                Stream *maskStr, int maskWidth, int maskHeight,
134                                GBool maskInvert);
135   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
136                                    int width, int height,
137                                    GfxImageColorMap *colorMap,
138                                    Stream *maskStr,
139                                    int maskWidth, int maskHeight,
140                                    GfxImageColorMap *maskColorMap);
141
142   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
143 #if xpdfUpdateVersion >= 16
144   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
145                                       GfxColorSpace *blendingColorSpace,
146                                       GBool isolated, GBool knockout,
147                                       GBool forSoftMask);
148   virtual void endTransparencyGroup(GfxState *state);
149   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
150   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
151   virtual void clearSoftMask(GfxState *state);
152 #endif
153  
154   //----- type 3 chars
155   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
156   virtual void endType3Char(GfxState *state);
157
158   virtual void type3D0(GfxState *state, double wx, double wy);
159   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
160
161   void preparePage(int pdfpage, int outputpage);
162
163   char* searchForSuitableFont(GfxFont*gfxFont);
164
165   void finish();
166
167   private:
168   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
169                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
170                                    GBool inlineImg, int mask, int *maskColors,
171                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
172   int setGfxFont(char*id, char*name, char*filename, double quality);
173   void strokeGfxline(GfxState *state, gfxline_t*line);
174   void clipToGfxLine(GfxState *state, gfxline_t*line);
175   void fillGfxLine(GfxState *state, gfxline_t*line);
176
177   char outer_clip_box; //whether the page clip box is still on
178
179   InfoOutputDev*info;
180   GFXOutputState states[64];
181   int statepos;
182
183   int currentpage;
184
185   PDFDoc*doc;
186   XRef*xref;
187
188   char* searchFont(char*name);
189   char* substituteFont(GfxFont*gfxFont, char*oldname);
190   char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
191   int t1id;
192   int textmodeinfo; // did we write "Text will be rendered as polygon" yet?
193   int jpeginfo; // did we write "File contains jpegs" yet?
194   int pbminfo; // did we write "File contains jpegs" yet?
195   int linkinfo; // did we write "File contains links" yet?
196   int ttfinfo; // did we write "File contains TrueType Fonts" yet?
197   int gradientinfo; // did we write "File contains Gradients yet?
198
199   int type3active; // are we between beginType3()/endType3()?
200
201   GfxState *laststate;
202
203   char type3Warning;
204
205   char* substitutetarget[256];
206   char* substitutesource[256];
207   int substitutepos;
208
209   /* upper left corner of clipping rectangle (cropbox)- needs to be
210      added to all drawing coordinates to give the impression that all
211      pages start at (0,0)*/
212   int clipmovex,clipmovey;
213
214   int user_movex,user_movey;
215   int user_clipx1,user_clipx2,user_clipy1,user_clipy2;
216
217   gfxline_t* current_text_stroke;
218   gfxline_t* current_text_clip;
219   char* current_font_id;
220   gfxfont_t* current_gfxfont;
221   gfxmatrix_t current_font_matrix;
222
223   fontlist_t* fontlist;
224
225   int*pages;
226   int pagebuflen;
227   int pagepos;
228
229   /* config */
230   int forceType0Fonts;
231   int config_use_fontconfig;
232
233   parameter_t*parameters;
234 };
235
236 #endif //__gfxoutputdev_h__