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