Mercurial > MadButterfly
comparison include/mb_graph_engine_cairo.h @ 465:d8181696b689 Android_Skia
Move functions into graphic engine layers.
Cairo and Skia have their own header files and C/C++ files. Some
functions are refactoried and move into graphic engine layer to make
reset of MadButterfly independently from graphic engines.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 12 Nov 2009 21:22:30 +0800 |
parents | |
children | 4dc0be6c044a |
comparison
equal
deleted
inserted
replaced
464:271212f325b4 | 465:d8181696b689 |
---|---|
1 #ifndef __MB_GE_CAIRO_H_ | |
2 #define __MB_GE_CAIRO_H_ | |
3 | |
4 #include <stdio.h> | |
5 #include <cairo.h> | |
6 #include <cairo-xlib.h> | |
7 #include "mb_img_ldr.h" | |
8 | |
9 /*! \defgroup mb_ge_cairo MadButterfly Graphic Engine with Cairo | |
10 * @{ | |
11 */ | |
12 #define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR | |
13 #define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE | |
14 #define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS | |
15 | |
16 #define mbe_ft_font_face_create_for_pattern cairo_ft_font_face_create_for_pattern | |
17 #define mbe_image_surface_create_from_png cairo_image_surface_create_from_png | |
18 #define mbe_pattern_add_color_stop_rgba cairo_pattern_add_color_stop_rgba | |
19 #define mbe_pattern_create_for_surface cairo_pattern_create_for_surface | |
20 #define mbe_scaled_font_text_extents cairo_scaled_font_text_extents | |
21 #define mbe_image_surface_get_stride cairo_image_surface_get_stride | |
22 #define mbe_image_surface_get_height cairo_image_surface_get_height | |
23 #define mbe_image_surface_get_width cairo_image_surface_get_width | |
24 #define mbe_image_surface_get_data cairo_image_surface_get_data | |
25 #define mbe_scaled_font_reference cairo_scaled_font_reference | |
26 #define mbe_pattern_create_radial cairo_pattern_create_radial | |
27 #define mbe_pattern_create_linear cairo_pattern_create_linear | |
28 #define mbe_xlib_surface_create cairo_xlib_surface_create | |
29 #define mbe_scaled_font_destroy cairo_scaled_font_destroy | |
30 #define mbe_font_face_reference cairo_font_face_reference | |
31 #define mbe_set_source_surface cairo_set_source_surface | |
32 #define mbe_scaled_font_status cairo_scaled_font_status | |
33 #define mbe_pattern_set_matrix cairo_pattern_set_matrix | |
34 #define mbe_font_face_destroy cairo_font_face_destroy | |
35 #define mbe_paint_with_alpha cairo_paint_with_alpha | |
36 #define mbe_font_face_status cairo_font_face_status | |
37 #define mbe_surface_destroy cairo_surface_destroy | |
38 #define mbe_set_source_rgba cairo_set_source_rgba | |
39 #define mbe_set_scaled_font cairo_set_scaled_font | |
40 #define mbe_pattern_destroy cairo_pattern_destroy | |
41 #define mbe_get_scaled_font cairo_get_scaled_font | |
42 #define mbe_set_source_rgb cairo_set_source_rgb | |
43 #define mbe_set_line_width cairo_set_line_width | |
44 #define mbe_get_font_face cairo_get_font_face | |
45 #define mbe_fill_preserve cairo_fill_preserve | |
46 #define mbe_set_operator cairo_set_operator | |
47 #define mbe_get_operator cairo_get_operator | |
48 #define mbe_set_source cairo_set_source | |
49 #define mbe_reset_clip cairo_reset_clip | |
50 #define mbe_get_target cairo_get_target | |
51 #define mbe_close_path cairo_close_path | |
52 #define mbe_text_path cairo_text_path | |
53 #define mbe_show_text cairo_show_text | |
54 #define mbe_rectangle cairo_rectangle | |
55 #define mbe_in_stroke cairo_in_stroke | |
56 #define mbe_new_path cairo_new_path | |
57 #define mbe_curve_to cairo_curve_to | |
58 #define mbe_restore cairo_restore | |
59 #define mbe_move_to cairo_move_to | |
60 #define mbe_line_to cairo_line_to | |
61 #define mbe_in_fill cairo_in_fill | |
62 #define mbe_destroy cairo_destroy | |
63 #define mbe_stroke cairo_stroke | |
64 #define mbe_create cairo_create | |
65 #define mbe_paint cairo_paint | |
66 #define mbe_save cairo_save | |
67 #define mbe_fill cairo_fill | |
68 #define mbe_clip cairo_clip | |
69 | |
70 typedef cairo_text_extents_t mbe_text_extents_t; | |
71 typedef cairo_scaled_font_t mbe_scaled_font_t; | |
72 typedef cairo_font_face_t mbe_font_face_t; | |
73 typedef cairo_operator_t mbe_operator_t; | |
74 typedef cairo_surface_t mbe_surface_t; | |
75 typedef cairo_pattern_t mbe_pattern_t; | |
76 typedef cairo_status_t mbe_status_t; | |
77 typedef cairo_matrix_t mbe_matrix_t; | |
78 typedef cairo_t mbe_t; | |
79 typedef float co_aix; | |
80 | |
81 | |
82 extern mbe_font_face_t * mbe_query_font_face(const char *family, | |
83 int slant, int weight); | |
84 extern void mbe_free_font_face(mbe_font_face_t *face); | |
85 | |
86 | |
87 static mbe_scaled_font_t * | |
88 mbe_scaled_font_create(mbe_font_face_t *face, mbe_matrix_t *fnt_mtx, | |
89 mbe_matrix_t *ctm) { | |
90 cairo_font_options_t *options; | |
91 mbe_scaled_font_t *scaled; | |
92 | |
93 options = cairo_font_options_create(); | |
94 if(options == NULL) | |
95 return NULL; | |
96 | |
97 scaled = cairo_scaled_font_create(face, fnt_mtx, ctm, options); | |
98 | |
99 cairo_font_options_destroy(options); | |
100 | |
101 return scaled; | |
102 } | |
103 | |
104 static mbe_surface_t * | |
105 mbe_image_surface_create_for_data(unsigned char *data, | |
106 mb_img_fmt_t fmt, | |
107 int width, int height, | |
108 int stride) { | |
109 cairo_format_t _fmt; | |
110 | |
111 switch(fmt) { | |
112 case MB_IFMT_ARGB32: | |
113 _fmt = CAIRO_FORMAT_ARGB32; | |
114 break; | |
115 case MB_IFMT_RGB24: | |
116 _fmt = CAIRO_FORMAT_RGB24; | |
117 break; | |
118 case MB_IFMT_A8: | |
119 _fmt = CAIRO_FORMAT_A8; | |
120 break; | |
121 case MB_IFMT_A1: | |
122 _fmt = CAIRO_FORMAT_A1; | |
123 break; | |
124 default: | |
125 return NULL; | |
126 } | |
127 return cairo_image_surface_create_for_data(data, _fmt, | |
128 width, height, stride); | |
129 } | |
130 | |
131 static mb_img_fmt_t | |
132 mbe_image_surface_get_format(mbe_surface_t *surface) { | |
133 cairo_format_t _fmt; | |
134 mb_img_fmt_t fmt; | |
135 | |
136 _fmt = cairo_image_surface_get_format(surface); | |
137 switch(_fmt) { | |
138 case CAIRO_FORMAT_ARGB32: | |
139 fmt = MB_IFMT_ARGB32; | |
140 break; | |
141 case CAIRO_FORMAT_RGB24: | |
142 fmt = MB_IFMT_RGB24; | |
143 break; | |
144 case CAIRO_FORMAT_A8: | |
145 fmt = MB_IFMT_A8; | |
146 break; | |
147 case CAIRO_FORMAT_A1: | |
148 fmt = MB_IFMT_A1; | |
149 break; | |
150 default: | |
151 fmt = MB_IFMT_DUMMY; | |
152 break; | |
153 } | |
154 | |
155 return fmt; | |
156 } | |
157 | |
158 static mbe_surface_t * | |
159 mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) { | |
160 cairo_format_t _fmt; | |
161 | |
162 switch(fmt) { | |
163 case MB_IFMT_ARGB32: | |
164 _fmt = CAIRO_FORMAT_ARGB32; | |
165 break; | |
166 case MB_IFMT_RGB24: | |
167 _fmt = CAIRO_FORMAT_RGB24; | |
168 break; | |
169 case MB_IFMT_A8: | |
170 _fmt = CAIRO_FORMAT_A8; | |
171 break; | |
172 case MB_IFMT_A1: | |
173 _fmt = CAIRO_FORMAT_A1; | |
174 break; | |
175 default: | |
176 return NULL; | |
177 } | |
178 | |
179 return cairo_image_surface_create(_fmt, width, height); | |
180 } | |
181 | |
182 static void | |
183 mbe_transform(mbe_t *mbe, const co_aix matrix[6]) { | |
184 cairo_matrix_t cmtx; | |
185 | |
186 cmtx.xx = matrix[0]; | |
187 cmtx.xy = matrix[1]; | |
188 cmtx.x0 = matrix[2]; | |
189 cmtx.yx = matrix[3]; | |
190 cmtx.yy = matrix[4]; | |
191 cmtx.y0 = matrix[5]; | |
192 | |
193 cairo_transform(mbe, &cmtx); | |
194 } | |
195 | |
196 static void | |
197 mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius, | |
198 co_aix angle_start, co_aix angle_stop) { | |
199 if(angle_start <= angle_stop) | |
200 cairo_arc(mbe, x, y, radius, angle_start, angle_stop); | |
201 else | |
202 cairo_arc_negative(mbe, x, y, radius, angle_start, angle_stop); | |
203 } | |
204 /* @} */ | |
205 | |
206 #endif /* __MB_GE_CAIRO_H_ */ |