Extracting parts of the formatting method into configuration and an options helper...
[cslatevm.git] / src / plugins / old / slate-cairo.c
blob459c440fd6db0a1f27eda66aeccbaf404a848653
1 // Workaround for OS X ExternalLibrary float problem.
3 #ifdef _MSC_VER
4 # pragma warning(disable: 4005) // warning in Cairo headers
5 #endif
7 #include <cairo.h>
8 #include <stdint.h>
11 typedef intptr_t slate_int_t;
13 #ifndef EXPORT
14 # ifdef _WIN32
15 # define EXPORT __declspec(dllexport)
16 # else
17 # define EXPORT
18 # endif
19 #endif
21 /******************************************************************************
22 * Construction / Destruction
23 ******************************************************************************/
25 EXPORT cairo_surface_t *image_surface_create_for_data(
26 unsigned char *data, slate_int_t format, slate_int_t width, slate_int_t height, slate_int_t stride)
28 return cairo_image_surface_create_for_data(data, format, width, height, stride);
31 EXPORT void surface_destroy(cairo_surface_t *surface)
33 cairo_surface_destroy(surface);
36 EXPORT cairo_t *create(cairo_surface_t *surface)
38 return cairo_create(surface);
41 EXPORT void destroy(cairo_t *context)
43 cairo_destroy(context);
46 /******************************************************************************
47 * Context
48 ******************************************************************************/
50 EXPORT void clip(cairo_t *context)
52 cairo_clip(context);
55 EXPORT void clip_preserve(cairo_t *context)
57 cairo_clip_preserve(context);
61 EXPORT void fill(cairo_t *context)
63 cairo_fill(context);
66 EXPORT void fill_preserve(cairo_t *context)
68 cairo_fill_preserve(context);
71 EXPORT void restore(cairo_t *context)
73 cairo_restore(context);
76 EXPORT void save(cairo_t *context)
78 cairo_save(context);
81 EXPORT slate_int_t get_line_width(cairo_t *context)
83 float f = (float)cairo_get_line_width(context);
84 return *(slate_int_t*)&f;
87 EXPORT void set_line_width(cairo_t *context, slate_int_t width)
89 cairo_set_line_width(context, *(float*)&width);
92 EXPORT void set_source_rgb(cairo_t *context, slate_int_t r, slate_int_t g, slate_int_t b)
94 cairo_set_source_rgb(context, *(float*)&r, *(float*)&g, *(float*)&b);
97 EXPORT void set_source_rgba(cairo_t *context, slate_int_t r, slate_int_t g, slate_int_t b, slate_int_t a)
99 cairo_set_source_rgba(context, *(float*)&r, *(float*)&g, *(float*)&b, *(float*)&a);
102 EXPORT void stroke(cairo_t *context)
104 cairo_stroke(context);
107 EXPORT void stroke_preserve(cairo_t *context)
109 cairo_stroke_preserve(context);
112 /******************************************************************************
113 * Path
114 ******************************************************************************/
116 EXPORT void close_path(cairo_t *context)
118 cairo_close_path(context);
121 EXPORT void line_to(cairo_t *context, slate_int_t x, slate_int_t y)
123 cairo_line_to(context, *(float*)&x, *(float*)&y);
126 EXPORT void move_to(cairo_t *context, slate_int_t x, slate_int_t y)
128 cairo_move_to(context, *(float*)&x, *(float*)&y);
131 EXPORT void new_path(cairo_t *context)
133 cairo_new_path(context);
136 EXPORT void rectangle(cairo_t *context, slate_int_t x, slate_int_t y, slate_int_t w, slate_int_t h)
138 cairo_rectangle(context, *(float*)&x, *(float*)&y, *(float*)&w, *(float*)&h);
141 /******************************************************************************
142 * Transformation
143 ******************************************************************************/
145 EXPORT void translate(cairo_t *context, slate_int_t tx, slate_int_t ty)
147 cairo_translate(context, *(float*)&tx, *(float*)&ty);
150 EXPORT void scale(cairo_t *context, slate_int_t sx, slate_int_t sy)
152 cairo_scale(context, *(float*)&sx, *(float*)&sy);
155 /******************************************************************************
156 * Text
157 ******************************************************************************/
159 EXPORT void select_font_face(cairo_t *context, const char *family, slate_int_t italic, slate_int_t bold)
161 cairo_select_font_face(
162 context,
163 family,
164 italic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
165 bold ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
168 EXPORT void set_font_size(cairo_t *context, slate_int_t size)
170 cairo_set_font_size(context, *(float*)&size);
173 EXPORT void show_text(cairo_t *context, const char *text)
175 if(!*text) // Cairo has insufficient checking
176 return;
177 cairo_show_text(context, text);
183 /* TODO list:
185 Context
186 ==========================================================
187 cairo_status_t cairo_status (cairo_t *cr);
188 cairo_surface_t* cairo_get_target (cairo_t *cr);
189 void cairo_set_source (cairo_t *cr,
190 cairo_pattern_t *source);
191 void cairo_set_source_surface (cairo_t *cr,
192 cairo_surface_t *surface,
193 double x,
194 double y);
195 cairo_pattern_t* cairo_get_source (cairo_t *cr);
196 void cairo_set_antialias (cairo_t *cr,
197 cairo_antialias_t antialias);
198 cairo_antialias_t cairo_get_antialias (cairo_t *cr);
199 void cairo_set_dash (cairo_t *cr,
200 double *dashes,
201 int num_dashes,
202 double offset);
203 void cairo_set_fill_rule (cairo_t *cr,
204 cairo_fill_rule_t fill_rule);
205 cairo_fill_rule_t cairo_get_fill_rule (cairo_t *cr);
206 void cairo_set_line_cap (cairo_t *cr,
207 cairo_line_cap_t line_cap);
208 cairo_line_cap_t cairo_get_line_cap (cairo_t *cr);
209 void cairo_set_line_join (cairo_t *cr,
210 cairo_line_join_t line_join);
211 cairo_line_join_t cairo_get_line_join (cairo_t *cr);
212 void cairo_set_miter_limit (cairo_t *cr,
213 double limit);
214 double cairo_get_miter_limit (cairo_t *cr);
215 void cairo_set_operator (cairo_t *cr,
216 cairo_operator_t op);
217 cairo_operator_t cairo_get_operator (cairo_t *cr);
218 void cairo_set_tolerance (cairo_t *cr,
219 double tolerance);
220 double cairo_get_tolerance (cairo_t *cr);
221 void cairo_reset_clip (cairo_t *cr);
222 void cairo_fill_extents (cairo_t *cr,
223 double *x1,
224 double *y1,
225 double *x2,
226 double *y2);
227 cairo_bool_t cairo_in_fill (cairo_t *cr,
228 double x,
229 double y);
230 void cairo_mask (cairo_t *cr,
231 cairo_pattern_t *pattern);
232 void cairo_mask_surface (cairo_t *cr,
233 cairo_surface_t *surface,
234 double surface_x,
235 double surface_y);
236 void cairo_paint (cairo_t *cr);
237 void cairo_paint_with_alpha (cairo_t *cr,
238 double alpha);
239 void cairo_stroke_extents (cairo_t *cr,
240 double *x1,
241 double *y1,
242 double *x2,
243 double *y2);
244 cairo_bool_t cairo_in_stroke (cairo_t *cr,
245 double x,
246 double y);
247 void cairo_copy_page (cairo_t *cr);
248 void cairo_show_page (cairo_t *cr);
250 Path
251 ==========================================================
252 cairo_path_t;
253 union cairo_path_data_t;
254 enum cairo_path_data_type_t;
255 cairo_path_t* cairo_copy_path (cairo_t *cr);
256 cairo_path_t* cairo_copy_path_flat (cairo_t *cr);
257 void cairo_path_destroy (cairo_path_t *path);
258 void cairo_append_path (cairo_t *cr,
259 cairo_path_t *path);
260 void cairo_get_current_point (cairo_t *cr,
261 double *x,
262 double *y);
263 void cairo_new_path (cairo_t *cr);
264 void cairo_close_path (cairo_t *cr);
265 void cairo_arc (cairo_t *cr,
266 double xc,
267 double yc,
268 double radius,
269 double angle1,
270 double angle2);
271 void cairo_arc_negative (cairo_t *cr,
272 double xc,
273 double yc,
274 double radius,
275 double angle1,
276 double angle2);
277 void cairo_curve_to (cairo_t *cr,
278 double x1,
279 double y1,
280 double x2,
281 double y2,
282 double x3,
283 double y3);
284 void cairo_line_to (cairo_t *cr,
285 double x,
286 double y);
287 void cairo_move_to (cairo_t *cr,
288 double x,
289 double y);
290 void cairo_rectangle (cairo_t *cr,
291 double x,
292 double y,
293 double width,
294 double height);
295 void cairo_glyph_path (cairo_t *cr,
296 cairo_glyph_t *glyphs,
297 int num_glyphs);
298 void cairo_text_path (cairo_t *cr,
299 const char *utf8);
300 void cairo_rel_curve_to (cairo_t *cr,
301 double dx1,
302 double dy1,
303 double dx2,
304 double dy2,
305 double dx3,
306 double dy3);
307 void cairo_rel_line_to (cairo_t *cr,
308 double dx,
309 double dy);
310 void cairo_rel_move_to (cairo_t *cr,
311 double dx,
312 double dy);
314 Pattern
315 ==========================================================
316 typedef cairo_pattern_t;
317 void cairo_pattern_add_color_stop_rgb
318 (cairo_pattern_t *pattern,
319 double offset,
320 double red,
321 double green,
322 double blue);
323 void cairo_pattern_add_color_stop_rgba
324 (cairo_pattern_t *pattern,
325 double offset,
326 double red,
327 double green,
328 double blue,
329 double alpha);
330 cairo_pattern_t* cairo_pattern_create_rgb (double red,
331 double green,
332 double blue);
333 cairo_pattern_t* cairo_pattern_create_rgba (double red,
334 double green,
335 double blue,
336 double alpha);
337 cairo_pattern_t* cairo_pattern_create_for_surface
338 (cairo_surface_t *surface);
339 cairo_pattern_t* cairo_pattern_create_linear
340 (double x0,
341 double y0,
342 double x1,
343 double y1);
344 cairo_pattern_t* cairo_pattern_create_radial
345 (double cx0,
346 double cy0,
347 double radius0,
348 double cx1,
349 double cy1,
350 double radius1);
351 void cairo_pattern_destroy (cairo_pattern_t *pattern);
352 cairo_pattern_t* cairo_pattern_reference (cairo_pattern_t *pattern);
353 cairo_status_t cairo_pattern_status (cairo_pattern_t *pattern);
354 enum cairo_extend_t;
355 void cairo_pattern_set_extend (cairo_pattern_t *pattern,
356 cairo_extend_t extend);
357 cairo_extend_t cairo_pattern_get_extend (cairo_pattern_t *pattern);
358 enum cairo_filter_t;
359 void cairo_pattern_set_filter (cairo_pattern_t *pattern,
360 cairo_filter_t filter);
361 cairo_filter_t cairo_pattern_get_filter (cairo_pattern_t *pattern);
362 void cairo_pattern_set_matrix (cairo_pattern_t *pattern,
363 const cairo_matrix_t *matrix);
364 void cairo_pattern_get_matrix (cairo_pattern_t *pattern,
365 cairo_matrix_t *matrix);
367 Transformation
368 ==========================================================
369 void cairo_translate (cairo_t *cr,
370 double tx,
371 double ty);
372 void cairo_rotate (cairo_t *cr,
373 double angle);
374 void cairo_transform (cairo_t *cr,
375 const cairo_matrix_t *matrix);
376 void cairo_set_matrix (cairo_t *cr,
377 const cairo_matrix_t *matrix);
378 void cairo_get_matrix (cairo_t *cr,
379 cairo_matrix_t *matrix);
380 void cairo_identity_matrix (cairo_t *cr);
381 void cairo_user_to_device (cairo_t *cr,
382 double *x,
383 double *y);
384 void cairo_user_to_device_distance (cairo_t *cr,
385 double *dx,
386 double *dy);
387 void cairo_device_to_user (cairo_t *cr,
388 double *x,
389 double *y);
390 void cairo_device_to_user_distance (cairo_t *cr,
391 double *dx,
392 double *dy);
394 Text
395 ==========================================================
396 cairo_glyph_t;
397 enum cairo_font_slant_t;
398 enum cairo_font_weight_t;
399 void cairo_set_font_matrix (cairo_t *cr,
400 const cairo_matrix_t *matrix);
401 void cairo_get_font_matrix (cairo_t *cr,
402 cairo_matrix_t *matrix);
403 void cairo_set_font_options (cairo_t *cr,
404 const cairo_font_options_t *options);
405 void cairo_get_font_options (cairo_t *cr,
406 cairo_font_options_t *options);
407 void cairo_show_glyphs (cairo_t *cr,
408 cairo_glyph_t *glyphs,
409 int num_glyphs);
410 cairo_font_face_t* cairo_get_font_face (cairo_t *cr);
411 void cairo_font_extents (cairo_t *cr,
412 cairo_font_extents_t *extents);
413 void cairo_set_font_face (cairo_t *cr,
414 cairo_font_face_t *font_face);
415 void cairo_text_extents (cairo_t *cr,
416 const char *utf8,
417 cairo_text_extents_t *extents);
418 void cairo_glyph_extents (cairo_t *cr,
419 cairo_glyph_t *glyphs,
420 int num_glyphs,
421 cairo_text_extents_t *extents);
423 ==========================================================