8012bba7631775eaa456cc81cd6d075407e5547d
[swftools.git] / lib / pdf / GFXOutputDev.h
1 #ifndef __gfxoutputdev_h__
2 #define __gfxoutputdev_h__
3
4 #include "../gfxdevice.h"
5 #include "../gfxsource.h"
6 #include "../gfxtools.h"
7
8 #include "config.h"
9 #include "InfoOutputDev.h"
10 #include "PDFDoc.h"
11 #include "GlobalParams.h"
12 #include "CommonOutputDev.h"
13
14 class GFXOutputState {
15     public:
16     int clipping;
17     int textRender;
18     char createsoftmask;
19     char transparencygroup;
20     char softmask;
21     char softmask_alpha;
22     char isolated;
23
24     gfxbbox_t clipbbox;
25
26     GFXOutputState();
27
28     gfxresult_t* grouprecording; // for transparency groups
29     gfxresult_t* softmaskrecording; // for soft masks
30
31     gfxdevice_t* olddevice;
32   
33     double *dashPattern;
34     int dashLength;
35     double dashStart;
36
37     GfxState*state;
38 };
39
40 typedef struct _feature
41 {
42     char*string;
43     struct _feature*next;
44 } feature_t;
45
46 void addGlobalFont(const char*filename);
47 void addGlobalLanguageDir(const char*dir);
48 void addGlobalFontDir(const char*dirname);
49
50 class GFXOutputGlobals {
51 public:
52   feature_t*featurewarnings;
53
54   int textmodeinfo; // did we write "Text will be rendered as polygon" yet?
55   int jpeginfo; // did we write "File contains jpegs" yet?
56   int pbminfo; // did we write "File contains jpegs" yet?
57   int linkinfo; // did we write "File contains links" yet?
58
59   GFXOutputGlobals();
60   ~GFXOutputGlobals();
61 };
62
63 class GFXOutputDev:  public CommonOutputDev {
64 public:
65   gfxdevice_t* device;
66
67   GFXOutputDev(InfoOutputDev*info, PDFDoc*doc);
68   virtual ~GFXOutputDev() ;
69
70   virtual void setDevice(gfxdevice_t*dev);
71   virtual void setMove(int x,int y);
72   virtual void setClip(int x1,int y1,int x2,int y2);
73   virtual void setParameter(const char*key, const char*value);
74   
75   // Start a page.
76   virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ;
77   virtual void endPage();
78
79   //----- get info about output device
80
81   // Does this device use upside-down coordinates?
82   // (Upside-down means (0,0) is the top left corner of the page.)
83   virtual GBool upsideDown();
84
85   // Does this device use drawChar() or drawString()?
86   virtual GBool useDrawChar();
87   
88   virtual GBool interpretType3Chars();
89   
90   //virtual GBool useShadedFills() { return gTrue; }
91
92   //----- link borders
93   virtual void processLink(Link *link, Catalog *catalog);
94
95   //----- save/restore graphics state
96   virtual void saveState(GfxState *state) ;
97   virtual void restoreState(GfxState *state) ;
98
99   //----- update graphics state
100
101   virtual void updateLineDash(GfxState *state);
102   virtual void updateFont(GfxState *state);
103   virtual void updateFontMatrix(GfxState *state);
104   virtual void updateFillColor(GfxState *state);
105   virtual void updateStrokeColor(GfxState *state);
106   virtual void updateLineWidth(GfxState *state);
107   virtual void updateLineJoin(GfxState *state);
108   virtual void updateLineCap(GfxState *state);
109   virtual void updateFillOpacity(GfxState *state);
110   virtual void updateStrokeOpacity(GfxState *state);
111   virtual void updateFillOverprint(GfxState *state);
112   virtual void updateStrokeOverprint(GfxState *state);
113   virtual void updateTransfer(GfxState *state);
114   
115   virtual void updateAll(GfxState *state) 
116   {
117       updateFont(state);
118       updateFillColor(state);
119       updateStrokeColor(state);
120       updateLineWidth(state);
121       updateLineJoin(state);
122       updateLineCap(state);
123   };
124
125   //----- path painting
126   virtual void stroke(GfxState *state) ;
127   virtual void fill(GfxState *state) ;
128   virtual void eoFill(GfxState *state) ;
129
130   //----- path clipping
131   virtual void clip(GfxState *state) ;
132   virtual void eoClip(GfxState *state) ;
133   virtual void clipToStrokePath(GfxState *state);
134  
135   //----- shaded fills
136   virtual GBool useTilingPatternFill();
137   virtual GBool useShadedFills();
138
139 #if (xpdfMajorVersion < 3) || (xpdfMinorVersion < 2) || (xpdfUpdateVersion < 7)
140   virtual void tilingPatternFill(GfxState *state, Object *str,
141                              int paintType, Dict *resDict,
142                              double *mat, double *bbox,
143                              int x0, int y0, int x1, int y1,
144                              double xStep, double yStep);
145 #else
146   virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
147                              int paintType, Dict *resDict,
148                              double *mat, double *bbox,
149                              int x0, int y0, int x1, int y1,
150                              double xStep, double yStep);
151 #endif
152   virtual GBool functionShadedFill(GfxState *state,
153                                    GfxFunctionShading *shading);
154   virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading);
155   virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading);
156
157   //----- text drawing
158   virtual void beginString(GfxState *state, GString *s) ;
159   virtual void endString(GfxState *state) ;
160   virtual void endTextObject(GfxState *state);
161   virtual void drawChar(GfxState *state, double x, double y,
162                         double dx, double dy,
163                         double originX, double originY,
164                         CharCode code, int nBytes, Unicode *u, int uLen);
165
166   //----- image drawing
167   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
168                              int width, int height, GBool invert,
169                              GBool inlineImg);
170   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
171                          int width, int height, GfxImageColorMap *colorMap,
172                          int *maskColors, GBool inlineImg);
173   virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
174                                int width, int height,
175                                GfxImageColorMap *colorMap,
176                                Stream *maskStr, int maskWidth, int maskHeight,
177                                GBool maskInvert);
178   virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
179                                    int width, int height,
180                                    GfxImageColorMap *colorMap,
181                                    Stream *maskStr,
182                                    int maskWidth, int maskHeight,
183                                    GfxImageColorMap *maskColorMap);
184
185   //----- transparency groups and soft masks (xpdf >= ~ 3.01.16)
186   virtual void beginTransparencyGroup(GfxState *state, double *bbox,
187                                       GfxColorSpace *blendingColorSpace,
188                                       GBool isolated, GBool knockout,
189                                       GBool forSoftMask);
190   virtual void endTransparencyGroup(GfxState *state);
191   virtual void paintTransparencyGroup(GfxState *state, double *bbox);
192   virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor);
193   virtual void clearSoftMask(GfxState *state);
194  
195   //----- type 3 chars
196   virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
197   virtual void endType3Char(GfxState *state);
198
199   virtual void type3D0(GfxState *state, double wx, double wy);
200   virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
201
202   char* searchForSuitableFont(GfxFont*gfxFont);
203
204   void finish();
205
206   virtual GBool useDrawForm();
207   virtual void drawForm(Ref id);
208   virtual GBool needNonText();
209
210   //virtual void dump();
211   //virtual void beginStringOp(GfxState *state);
212   //virtual void drawString(GfxState *state, GString *s);
213   //virtual void endStringOp(GfxState *state);
214   //virtual GBool getVectorAntialias() { return gFalse; }
215   //virtual void setVectorAntialias(GBool vaa) {}
216   //virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
217
218   virtual void setPageMap(int*pagemap, int pagemap_len);
219
220   private:
221   gfxline_t* gfxPath_to_gfxline(GfxState*state, GfxPath*path, int closed, int user_movex, int user_movey);
222
223   void transformXY(GfxState*state, double x, double y, double*nx, double*ny);
224
225   void drawGeneralImage(GfxState *state, Object *ref, Stream *str,
226                                    int width, int height, GfxImageColorMap*colorMap, GBool invert,
227                                    GBool inlineImg, int mask, int *maskColors,
228                                    Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GfxImageColorMap*maskColorMap);
229
230   void strokeGfxline(GfxState *state, gfxline_t*line, int flags);
231   void clipToGfxLine(GfxState *state, gfxline_t*line, char evenodd);
232   void fillGfxLine(GfxState *state, gfxline_t*line, char evenodd);
233
234   gfxfont_t* createGfxFont(GfxFont*xpdffont, FontInfo*src);
235
236   void showfeature(const char*feature,char fully, char warn);
237   void warnfeature(const char*feature,char fully);
238   void infofeature(const char*feature);
239   
240   char* searchFont(const char*name);
241   char* substituteFont(GfxFont*gfxFont, char*oldname);
242   char* writeEmbeddedFontToFile(XRef*ref, GfxFont*font);
243
244   /* for page mapping */
245   int* page2page;
246   int num_pages;
247
248
249   int currentpage;
250   char outer_clip_box; //whether the page clip box is still on
251   InfoOutputDev*info;
252   GFXOutputState states[64];
253   int statepos;
254
255   PDFDoc*doc;
256   XRef*xref;
257
258   int type3active; // are we between beginType3()/endType3()?
259
260   GfxState *laststate;
261
262   int user_movex,user_movey;
263   int user_clipx1,user_clipx2,user_clipy1,user_clipy2;
264
265   /* upper left corner of clipping rectangle (cropbox)- needs to be
266      added to all drawing coordinates to give the impression that all
267      pages start at (0,0)*/
268   int clipmovex;
269   int clipmovey;
270
271   gfxline_t* current_text_stroke;
272   gfxline_t* current_text_clip;
273   gfxfont_t* current_gfxfont;
274   FontInfo*current_fontinfo;
275   gfxmatrix_t current_font_matrix;
276
277   gfxfont_t* last_char_gfxfont;
278   int last_char;
279   double last_char_x;
280   double last_char_y;
281   char last_char_was_space;
282
283   /* config */
284   int config_use_fontconfig;
285   int config_break_on_warning;
286   int config_remapunicode;
287   int config_transparent;
288   int config_extrafontdata;
289   int config_convertgradients;
290   int config_disable_polygon_conversion;
291   int config_multiply;
292   int config_bigchar;
293   int config_drawonlyshapes;
294   char* config_linkdatafile;
295   double config_fontquality;
296 };
297
298 class GFXGlobalParams:  public GlobalParams {
299     public:
300     GFXGlobalParams();
301     ~GFXGlobalParams();
302     virtual DisplayFontParam *getDisplayFont(GString *fontName);
303 };
304
305 #endif //__gfxoutputdev_h__