4 // Authors: Duncan Mak (duncan@ximian.com)
5 // Hisham Mardam Bey (hisham.mardambey@gmail.com)
7 // (C) Ximian, Inc. 2003
9 // This is a simplistic binding of the Cairo API to C#. All functions
10 // in cairo.h are transcribed into their C# equivelants and all
11 // enumerations are also listed here.
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Runtime.InteropServices;
40 internal class CairoAPI
42 internal const string CairoImp = "libcairo-2.dll";
45 // Manipulating state objects
47 [DllImport (CairoImp)]
48 public static extern IntPtr cairo_create (IntPtr target);
50 [DllImport (CairoImp)]
51 public static extern void cairo_reference (IntPtr cr);
53 [DllImport (CairoImp)]
54 public static extern void cairo_destroy (IntPtr cr);
56 [DllImport (CairoImp)]
57 public static extern void cairo_save (IntPtr cr);
59 [DllImport (CairoImp)]
60 public static extern void cairo_restore (IntPtr cr);
65 [DllImport (CairoImp)]
66 public static extern IntPtr cairo_image_surface_create_for_data (
67 IntPtr data, Cairo.Format format, int width, int height, int stride);
69 [DllImport (CairoImp)]
70 public static extern void cairo_set_operator (IntPtr cr, Cairo.Operator op);
72 [DllImport (CairoImp)]
73 public static extern void cairo_set_source_rgba (IntPtr cr, double red, double green, double blue, double alpha);
75 [DllImport (CairoImp)]
76 public static extern void cairo_set_source_rgb (IntPtr cr, double red, double green, double blue);
78 [DllImport (CairoImp)]
79 public static extern void cairo_set_source (IntPtr cr, IntPtr pattern);
81 [DllImport (CairoImp)]
82 public static extern IntPtr cairo_get_source (IntPtr cr);
84 [DllImport (CairoImp)]
85 public static extern void cairo_set_tolerance (IntPtr cr, double tolerance);
87 [DllImport (CairoImp)]
88 public static extern void cairo_set_fill_rule (IntPtr cr, Cairo.FillRule fill_rule);
90 [DllImport (CairoImp)]
91 public static extern void cairo_set_line_width (IntPtr cr, double width);
93 [DllImport (CairoImp)]
94 public static extern void cairo_set_line_cap (IntPtr cr, Cairo.LineCap line_cap);
96 [DllImport (CairoImp)]
97 public static extern void cairo_set_line_join (IntPtr cr, Cairo.LineJoin line_join);
99 [DllImport (CairoImp)]
100 public static extern void cairo_set_dash (IntPtr cr, double [] dashes, int ndash, double offset);
102 [DllImport (CairoImp)]
103 public static extern void cairo_set_miter_limit (IntPtr cr, double limit);
105 [DllImport (CairoImp)]
106 public static extern void cairo_translate (IntPtr cr, double tx, double ty);
108 [DllImport (CairoImp)]
109 public static extern void cairo_scale (IntPtr cr, double sx, double sy);
111 [DllImport (CairoImp)]
112 public static extern void cairo_rotate (IntPtr cr, double angle);
114 [DllImport (CairoImp)]
115 public static extern void cairo_transform (IntPtr cr, Matrix matrix);
117 [DllImport (CairoImp)]
118 public static extern void cairo_set_matrix (IntPtr cr, Matrix matrix);
120 [DllImport (CairoImp)]
121 public static extern void cairo_identity_matrix (IntPtr cr);
123 [DllImport (CairoImp)]
124 public static extern void cairo_user_to_device (IntPtr cr, ref double x, ref double y);
126 [DllImport (CairoImp)]
127 public static extern void cairo_user_to_device_distance (IntPtr cr, ref double dx, ref double dy);
129 [DllImport (CairoImp)]
130 public static extern void cairo_device_to_user (IntPtr cr, ref double x, ref double y);
132 [DllImport (CairoImp)]
133 public static extern void cairo_device_to_user_distance (IntPtr cr, ref double dx, ref double dy);
138 [DllImport (CairoImp)]
139 public static extern void cairo_new_path (IntPtr cr);
141 [DllImport (CairoImp)]
142 public static extern void cairo_move_to (IntPtr cr, double x, double y);
144 [DllImport (CairoImp)]
145 public static extern void cairo_line_to (IntPtr cr, double x, double y);
147 [DllImport (CairoImp)]
148 public static extern void cairo_curve_to (
149 IntPtr cr, double x1, double y1, double x2, double y2, double x3, double y3);
151 [DllImport (CairoImp)]
152 public static extern void cairo_arc (
153 IntPtr cr, double xc, double yc, double radius, double angel1, double angel2);
155 [DllImport (CairoImp)]
156 public static extern void cairo_arc_negative (
157 IntPtr cr, double xc, double yc, double radius, double angel1, double angel2);
159 [DllImport (CairoImp)]
160 public static extern void cairo_rel_move_to (IntPtr cr, double dx, double dy);
162 [DllImport (CairoImp)]
163 public static extern void cairo_rel_line_to (IntPtr cr, double dx, double dy);
165 [DllImport (CairoImp)]
166 public static extern void cairo_rel_curve_to (
167 IntPtr cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
169 [DllImport (CairoImp)]
170 public static extern void cairo_rectangle (IntPtr cr, double x, double y, double width, double height);
172 [DllImport (CairoImp)]
173 public static extern void cairo_close_path (IntPtr cr);
178 [DllImport (CairoImp)]
179 public static extern void cairo_stroke (IntPtr cr);
181 [DllImport (CairoImp)]
182 public static extern void cairo_stroke_preserve (IntPtr cr);
184 [DllImport (CairoImp)]
185 public static extern void cairo_stroke_extents (IntPtr cr, double x1, double y1, double x2, double y2);
187 [DllImport (CairoImp)]
188 public static extern void cairo_fill (IntPtr cr);
190 [DllImport (CairoImp)]
191 public static extern void cairo_fill_extents (IntPtr cr, double x1, double y1, double x2, double y2);
193 [DllImport (CairoImp)]
194 public static extern void cairo_fill_preserve (IntPtr cr);
196 [DllImport (CairoImp)]
197 public static extern void cairo_copy_page (IntPtr cr);
199 [DllImport (CairoImp)]
200 public static extern void cairo_show_page (IntPtr cr);
202 [DllImport (CairoImp)]
203 public static extern void cairo_clip (IntPtr cr);
205 [DllImport (CairoImp)]
206 public static extern void cairo_clip_preserve (IntPtr cr);
208 [DllImport (CairoImp)]
209 public static extern void cairo_reset_clip (IntPtr cr);
214 [DllImport (CairoImp)]
215 public static extern void cairo_select_font_face (IntPtr cr,
220 [DllImport (CairoImp)]
221 public static extern void cairo_set_font_size (IntPtr cr,
224 [DllImport (CairoImp)]
225 public static extern void cairo_set_font_matrix (IntPtr cr, Matrix matrix);
227 [DllImport (CairoImp)]
228 public static extern void cairo_show_text (IntPtr cr, string utf8);
230 [DllImport (CairoImp)]
231 public static extern void cairo_font_extents (IntPtr source, ref FontExtents extents);
233 [DllImport (CairoImp)]
234 public static extern void cairo_show_glyphs (IntPtr ct, IntPtr glyphs, int num_glyphs);
236 [DllImport (CairoImp)]
237 public static extern void cairo_text_path (IntPtr ct, string utf8);
239 [DllImport (CairoImp)]
240 public static extern void cairo_text_extents (IntPtr cr, string utf8, ref TextExtents extents);
242 [DllImport (CairoImp)]
243 public static extern void cairo_glyph_path (IntPtr ct, IntPtr glyphs, int num_glyphs);
248 [DllImport (CairoImp)]
249 public static extern void cairo_set_source_surface (IntPtr cr, IntPtr surface, int width, int height);
251 [DllImport (CairoImp)]
252 internal static extern void cairo_mask (IntPtr cr, IntPtr pattern);
254 [DllImport (CairoImp)]
255 internal static extern void cairo_mask_surface (IntPtr cr, IntPtr surface, double x, double y);
257 [DllImport (CairoImp)]
258 public static extern void cairo_paint (IntPtr cr);
260 [DllImport (CairoImp)]
261 public static extern void cairo_paint_with_alpha (IntPtr cr, double alpha);
263 [DllImport (CairoImp)]
264 public static extern IntPtr cairo_image_surface_create_from_png (string filename);
266 [DllImport (CairoImp)]
267 public static extern int cairo_image_surface_get_width (IntPtr surface);
269 [DllImport (CairoImp)]
270 public static extern int cairo_image_surface_get_height (IntPtr surface);
275 [DllImport (CairoImp)]
276 public static extern bool cairo_in_stroke (IntPtr cr, double x, double y);
278 [DllImport (CairoImp)]
279 public static extern bool cairo_in_fill (IntPtr cr, double x, double y);
281 [DllImport (CairoImp)]
282 public static extern Cairo.Operator cairo_get_operator (IntPtr cr);
284 [DllImport (CairoImp)]
285 public static extern double cairo_get_tolerance (IntPtr cr);
287 [DllImport (CairoImp)]
288 public static extern void cairo_get_current_point (
289 IntPtr cr, out double x, out double y);
291 [DllImport (CairoImp)]
292 public static extern Cairo.FillRule cairo_get_fill_rule (IntPtr cr);
294 [DllImport (CairoImp)]
295 public static extern double cairo_get_line_width (IntPtr cr);
297 [DllImport (CairoImp)]
298 public static extern LineCap cairo_get_line_cap (IntPtr cr);
300 [DllImport (CairoImp)]
301 public static extern LineJoin cairo_get_line_join (IntPtr cr);
303 [DllImport (CairoImp)]
304 public static extern double cairo_get_miter_limit (IntPtr cr);
306 [DllImport (CairoImp)]
307 public static extern void cairo_get_matrix (IntPtr cr, Matrix matrix);
309 [DllImport (CairoImp)]
310 public static extern IntPtr cairo_get_target (IntPtr cr);
313 // Error status queries
315 [DllImport (CairoImp)]
316 public static extern Cairo.Status cairo_status (IntPtr cr);
319 // Surface Manipulation
322 [DllImport (CairoImp)]
323 public static extern IntPtr cairo_xlib_surface_create (IntPtr dpi,
324 IntPtr win, IntPtr visual, int w, int h);
326 [DllImport (CairoImp)]
327 public static extern void cairo_xlib_surface_set_drawable (IntPtr surface, IntPtr drawable, int width, int height);
329 [DllImport (CairoImp)]
330 public static extern void cairo_xlib_surface_set_size (IntPtr surface, int width, int height);
332 [DllImport (CairoImp)]
333 public static extern Cairo.Status cairo_surface_finish (IntPtr surface);
335 [DllImport (CairoImp)]
336 internal static extern Cairo.Status cairo_surface_status (IntPtr surface);
338 [DllImport (CairoImp)]
339 public static extern void cairo_surface_set_device_offset (IntPtr surface,
342 [DllImport (CairoImp)]
343 public static extern IntPtr cairo_image_surface_create_for_data (
344 string data, Cairo.Format format, int width, int height, int stride);
346 [DllImport (CairoImp)]
347 public static extern IntPtr cairo_image_surface_create (Cairo.Format format, int width,
351 [DllImport (CairoImp)]
352 public static extern IntPtr cairo_surface_create_similar (
353 IntPtr surface, Cairo.Content content, int width, int height);
355 [DllImport (CairoImp)]
356 public static extern void cairo_surface_reference (IntPtr surface);
358 [DllImport (CairoImp)]
359 public static extern void cairo_surface_destroy (IntPtr surface);
361 [DllImport (CairoImp)]
362 public static extern void cairo_surface_write_to_png (IntPtr surface, string filename);
364 [DllImport (CairoImp)]
365 public static extern IntPtr cairo_pdf_surface_create (string filename, double width, double height);
367 [DllImport (CairoImp)]
368 public static extern void cairo_pdf_surface_set_dpi (IntPtr surface, double x_dpi, double y_dpi);
370 [DllImport (CairoImp)]
371 public static extern IntPtr cairo_ps_surface_create (string filename, double width, double height);
373 [DllImport (CairoImp)]
374 public static extern void cairo_ps_surface_set_dpi (IntPtr surface, double x_dpi, double y_dpi);
376 [DllImport (CairoImp)]
377 public static extern IntPtr cairo_win32_surface_create (IntPtr hdc);
383 [DllImport (CairoImp)]
384 public static extern void cairo_matrix_init_translate (Matrix matrix, double tx, double ty);
386 [DllImport (CairoImp)]
387 public static extern void cairo_matrix_translate (Matrix matrix, double tx, double ty);
389 [DllImport (CairoImp)]
390 public static extern void cairo_matrix_init_identity (Matrix matrix);
392 [DllImport (CairoImp)]
393 public static extern void cairo_matrix_init_scale (Matrix matrix, double sx, double sy);
395 [DllImport (CairoImp)]
396 public static extern void cairo_matrix_scale (Matrix matrix, double sx, double sy);
398 [DllImport (CairoImp)]
399 public static extern void cairo_matrix_init_rotate (Matrix matrix, double radians);
401 [DllImport (CairoImp)]
402 public static extern void cairo_matrix_rotate (Matrix matrix, double radians);
404 [DllImport (CairoImp)]
405 public static extern Cairo.Status cairo_matrix_invert (Matrix matrix);
407 [DllImport (CairoImp)]
408 public static extern void cairo_matrix_multiply (Matrix result, Matrix a, Matrix b);
410 [DllImport (CairoImp)]
411 public static extern void cairo_matrix_transform_distance (Matrix matrix, ref double dx, ref double dy);
413 [DllImport (CairoImp)]
414 public static extern void cairo_matrix_transform_point (Matrix matrix, ref double x, ref double y);
419 [DllImport (CairoImp)]
420 public static extern IntPtr cairo_pattern_create_for_surface (IntPtr surface);
422 [DllImport (CairoImp)]
423 public static extern IntPtr cairo_pattern_create_linear (double x0, double y0,
424 double x1, double y1);
426 [DllImport (CairoImp)]
427 public static extern IntPtr cairo_pattern_create_radial (double cx0, double cy0,
428 double radius0, double cx1, double cy1, double radius1);
430 [DllImport (CairoImp)]
431 public static extern IntPtr cairo_pattern_create_rgb (double r,
435 [DllImport (CairoImp)]
436 public static extern IntPtr cairo_pattern_create_rgba (double r,
441 [DllImport (CairoImp)]
442 public static extern void cairo_pattern_reference (IntPtr pattern);
444 [DllImport (CairoImp)]
445 public static extern void cairo_pattern_destroy (IntPtr pattern);
447 [DllImport (CairoImp)]
448 public static extern Status cairo_pattern_add_color_stop_rgba (IntPtr pattern,
449 double offset, double red, double green, double blue, double alpha);
451 [DllImport (CairoImp)]
452 public static extern Status cairo_pattern_add_color_stop_rgb (IntPtr pattern,
453 double offset, double red, double green, double blue);
455 [DllImport (CairoImp)]
456 public static extern Status cairo_pattern_set_matrix (IntPtr pattern, Matrix matrix);
458 [DllImport (CairoImp)]
459 public static extern Status cairo_pattern_get_matrix (IntPtr pattern, Matrix matrix);
461 [DllImport (CairoImp)]
462 public static extern Status cairo_pattern_set_extend (IntPtr pattern, Extend extend);
464 [DllImport (CairoImp)]
465 public static extern Extend cairo_pattern_get_extend (IntPtr pattern);
467 [DllImport (CairoImp)]
468 public static extern Status cairo_pattern_set_filter (IntPtr pattern, Filter filter);
470 [DllImport (CairoImp)]
471 public static extern Filter cairo_pattern_get_filter (IntPtr pattern);
473 [DllImport (CairoImp)]
474 public static extern Status cairo_pattern_status (IntPtr pattern);
476 [DllImport (CairoImp)]
477 public static extern void cairo_set_antialias (IntPtr cr, Antialias antialias);
479 [DllImport (CairoImp)]
480 public static extern Antialias cairo_get_antialias (IntPtr cr);
488 public enum Antialias {
495 public enum Content {
508 public enum Operator {
528 public enum FillRule {
533 public enum LineCap {
537 public enum LineJoin {
573 public enum FontSlant {
579 public enum FontWeight {
590 [StructLayout(LayoutKind.Sequential)]
591 public struct FontExtents
593 public double Ascent;
594 public double Descent;
595 public double Height;
596 public double MaxXAdvance;
597 public double MaxYAdvance;
601 [StructLayout(LayoutKind.Sequential)]
602 public struct TextExtents
604 public double XBearing;
605 public double YBearing;
607 public double Height;
608 public double XAdvance;
609 public double YAdvance;
612 [StructLayout(LayoutKind.Sequential)]