polygon intersector: added horizontal line reconstruction
[swftools.git] / lib / gfxdevice.h
1 #ifndef __gfxdevice_h__
2 #define __gfxdevice_h__
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #define GFX_SUBPIXEL 2560
9
10 typedef double gfxcoord_t;
11     
12 typedef enum {gfx_moveTo, gfx_lineTo, gfx_splineTo} gfx_linetype;
13 typedef enum {gfx_joinMiter, gfx_joinRound, gfx_joinBevel} gfx_joinType;
14 typedef enum {gfx_capButt, gfx_capRound, gfx_capSquare} gfx_capType;
15
16 typedef struct _gfxline
17 {
18     gfx_linetype type;
19     gfxcoord_t x,y;
20     gfxcoord_t sx,sy;
21     struct _gfxline*next; /*NULL=end*/
22 } gfxline_t;
23
24 typedef struct _gfxglyph
25 {
26     gfxline_t*line;
27     gfxcoord_t advance;
28
29     int unicode; // array?
30     const char*name;
31 } gfxglyph_t;
32
33 typedef struct _gfxfont
34 {
35     const char*id;
36     int num_glyphs;
37     int max_unicode;
38     
39     double ascent,descent;
40
41     gfxglyph_t*glyphs;
42     int* unicode2glyph;
43 } gfxfont_t;
44
45 typedef struct _gfxcolor
46 {
47     unsigned char a;
48     unsigned char r;
49     unsigned char g;
50     unsigned char b;
51 } gfxcolor_t;
52
53 typedef struct _gfxmatrix
54 {
55     double m00,m10,tx;
56     double m01,m11,ty;
57 } gfxmatrix_t;
58
59 typedef struct _gfximage
60 {
61     /* if the data contains an alpha layer (a != 255), the
62        r,g,b values will have to be premultiplied */
63     gfxcolor_t*data;
64     int width;
65     int height;
66 } gfximage_t;
67
68 /* gradients: A radial gradient will start at 0,0 and have a radius of 1,0 
69               An axial gradient starts at -1,0 and ends at 1,0
70  */
71 typedef enum {gfxgradient_radial, gfxgradient_linear} gfxgradienttype_t;
72 typedef struct _gfxgradient
73 {
74     gfxcolor_t color;
75     float pos; // 0.0 - 1.0
76     struct _gfxgradient*next; //NULL=end
77 } gfxgradient_t;
78
79 typedef struct _gfxcxform
80 {
81     float rr,rg,rb,ra, tr;
82     float gr,gg,gb,ga, tg;
83     float br,bg,bb,ba, tb;
84     float ar,ag,ab,aa, ta;
85 } gfxcxform_t;
86
87 typedef struct _gfxbbox
88 {
89     gfxcoord_t xmin, ymin, xmax, ymax;
90 } gfxbbox_t;
91
92 typedef struct _gfxresult
93 {
94     void (*write)(struct _gfxresult*gfx, int filedesc);
95     int (*save)(struct _gfxresult*gfx, const char*filename);
96     void* (*get)(struct _gfxresult*gfx, const char*name);
97     void (*destroy)(struct _gfxresult*gfx);
98
99     void*internal;
100 } gfxresult_t;
101
102 typedef struct _gfxdevice
103 {
104     const char* name; // gfx device name
105
106     int (*setparameter)(struct _gfxdevice*dev, const char*key, const char*value);
107
108     void (*startpage)(struct _gfxdevice*dev, int width, int height);
109
110     void (*startclip)(struct _gfxdevice*dev, gfxline_t*line);
111     void (*endclip)(struct _gfxdevice*dev);
112     void (*stroke)(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit);
113     void (*fill)(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color);
114     void (*fillbitmap)(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*imgcoord2devcoord, gfxcxform_t*cxform); //cxform? tiling?
115     void (*fillgradient)(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*gradcoord2devcoord); //?
116
117     /* deprecated */ void (*addfont)(struct _gfxdevice*dev, gfxfont_t*font);
118
119     void (*drawchar)(struct _gfxdevice*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
120
121     void (*drawlink)(struct _gfxdevice*dev, gfxline_t*line, const char*action);
122     
123     void (*endpage)(struct _gfxdevice*dev);
124     
125     const char* (*geterror)();
126     
127     gfxresult_t* (*finish)(struct _gfxdevice*dev);
128
129     void* internal;
130 } gfxdevice_t;
131
132 #ifdef __cplusplus
133 }
134 #endif
135
136 #endif //__gfxdevice_h__