fixed bug in jpeg2000 decoding
[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 _gfxkerning
34 {
35     int c1,c2,advance;
36 } gfxkerning_t;
37
38 typedef struct _gfxfont
39 {
40     const char*id;
41     int num_glyphs;
42     int max_unicode;
43     
44     double ascent,descent;
45
46     gfxglyph_t*glyphs;
47     int* unicode2glyph;
48
49     gfxkerning_t*kerning;
50     int kerning_size;
51 } gfxfont_t;
52
53 typedef struct _gfxcolor
54 {
55     unsigned char a;
56     unsigned char r;
57     unsigned char g;
58     unsigned char b;
59 } gfxcolor_t;
60
61 typedef struct _gfxmatrix
62 {
63     double m00,m10,tx;
64     double m01,m11,ty;
65 } gfxmatrix_t;
66
67 typedef struct _gfximage
68 {
69     /* if the data contains an alpha layer (a != 255), the
70        r,g,b values will have to be premultiplied */
71     gfxcolor_t*data;
72     int width;
73     int height;
74 } gfximage_t;
75
76 /* gradients: A radial gradient will start at 0,0 and have a radius of 1,0 
77               An axial gradient starts at -1,0 and ends at 1,0
78  */
79 typedef enum {gfxgradient_radial, gfxgradient_linear} gfxgradienttype_t;
80 typedef struct _gfxgradient
81 {
82     gfxcolor_t color;
83     float pos; // 0.0 - 1.0
84     struct _gfxgradient*next; //NULL=end
85 } gfxgradient_t;
86
87 typedef struct _gfxcxform
88 {
89     float rr,rg,rb,ra, tr;
90     float gr,gg,gb,ga, tg;
91     float br,bg,bb,ba, tb;
92     float ar,ag,ab,aa, ta;
93 } gfxcxform_t;
94
95 typedef struct _gfxbbox
96 {
97     gfxcoord_t xmin, ymin, xmax, ymax;
98 } gfxbbox_t;
99
100 typedef struct _gfxresult
101 {
102     void (*write)(struct _gfxresult*gfx, int filedesc);
103     int (*save)(struct _gfxresult*gfx, const char*filename);
104     void* (*get)(struct _gfxresult*gfx, const char*name);
105     void (*destroy)(struct _gfxresult*gfx);
106
107     void*internal;
108 } gfxresult_t;
109
110 typedef struct _gfxdevice
111 {
112     const char* name; // gfx device name
113
114     int (*setparameter)(struct _gfxdevice*dev, const char*key, const char*value);
115
116     void (*startpage)(struct _gfxdevice*dev, int width, int height);
117
118     void (*startclip)(struct _gfxdevice*dev, gfxline_t*line);
119     void (*endclip)(struct _gfxdevice*dev);
120     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);
121     void (*fill)(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color);
122
123     /* expects alpha channel in image to be non-premultiplied */
124     void (*fillbitmap)(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*imgcoord2devcoord, gfxcxform_t*cxform); //cxform? tiling?
125
126     void (*fillgradient)(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*gradcoord2devcoord); //?
127
128     void (*addfont)(struct _gfxdevice*dev, gfxfont_t*font);
129
130     void (*drawchar)(struct _gfxdevice*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
131
132     void (*drawlink)(struct _gfxdevice*dev, gfxline_t*line, const char*action);
133     
134     void (*endpage)(struct _gfxdevice*dev);
135     
136     const char* (*geterror)();
137     
138     gfxresult_t* (*finish)(struct _gfxdevice*dev);
139
140     void* internal;
141 } gfxdevice_t;
142
143 #ifdef __cplusplus
144 }
145 #endif
146
147 #endif //__gfxdevice_h__