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