4 // Author: Duncan Mak (duncan@ximian.com)
6 // (C) Ximian, Inc. 2003
8 // This is a simplistic binding of the Cairo API to C#. All functions
9 // in cairo.h are transcribed into their C# equivelants and all
10 // enumerations are also listed here.
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Runtime.InteropServices;
42 internal const string CairoImp = "cairo";
45 // Manipulating state objects
47 [DllImport (CairoImp)]
48 public static extern IntPtr cairo_create ();
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);
62 [DllImport (CairoImp)]
63 public static extern void cairo_copy (out IntPtr dest, IntPtr src);
68 [DllImport (CairoImp)]
69 public static extern void cairo_set_target_surface (IntPtr cr, IntPtr surface);
71 [DllImport (CairoImp)]
72 public static extern void cairo_set_target_image (
73 IntPtr cr, string data, Cairo.Format format, int width, int height, int stride);
75 [DllImport (CairoImp)]
76 public static extern void cairo_set_target_drawable (
77 IntPtr ct, IntPtr display, IntPtr drawable);
79 [DllImport (CairoImp)]
80 public static extern void cairo_set_operator (IntPtr cr, Cairo.Operator op);
82 [DllImport (CairoImp)]
83 public static extern void cairo_set_rgb_color (IntPtr cr, double red, double green, double blue);
85 [DllImport (CairoImp)]
86 public static extern void cairo_set_alpha (IntPtr cr, double alpha);
88 [DllImport (CairoImp)]
89 public static extern void cairo_set_pattern (IntPtr cr, IntPtr pattern);
91 [DllImport (CairoImp)]
92 public static extern void cairo_set_tolerance (IntPtr cr, double tolerance);
94 [DllImport (CairoImp)]
95 public static extern void cairo_set_fill_rule (IntPtr cr, Cairo.FillRule fill_rule);
97 [DllImport (CairoImp)]
98 public static extern void cairo_set_line_width (IntPtr cr, double width);
100 [DllImport (CairoImp)]
101 public static extern void cairo_set_line_cap (IntPtr cr, Cairo.LineCap line_cap);
103 [DllImport (CairoImp)]
104 public static extern void cairo_set_line_join (IntPtr cr, Cairo.LineJoin line_join);
106 [DllImport (CairoImp)]
107 public static extern void cairo_set_dash (IntPtr cr, double [] dashes, int ndash, double offset);
109 [DllImport (CairoImp)]
110 public static extern void cairo_set_miter_limit (IntPtr cr, double limit);
112 [DllImport (CairoImp)]
113 public static extern void cairo_translate (IntPtr cr, double tx, double ty);
115 [DllImport (CairoImp)]
116 public static extern void cairo_scale (IntPtr cr, double sx, double sy);
118 [DllImport (CairoImp)]
119 public static extern void cairo_rotate (IntPtr cr, double angle);
121 [DllImport (CairoImp)]
122 public static extern void cairo_concat_matrix (IntPtr cr, IntPtr matrix);
124 [DllImport (CairoImp)]
125 public static extern void cairo_set_matrix (IntPtr cr, IntPtr matrix);
127 [DllImport (CairoImp)]
128 public static extern void cairo_default_matrix (IntPtr cr);
130 [DllImport (CairoImp)]
131 public static extern void cairo_identity_matrix (IntPtr cr);
133 [DllImport (CairoImp)]
134 public static extern void cairo_transform_point (IntPtr cr, ref double x, ref double y);
136 [DllImport (CairoImp)]
137 public static extern void cairo_transform_distance (IntPtr cr, ref double dx, ref double dy);
139 [DllImport (CairoImp)]
140 public static extern void cairo_inverse_transform_point (IntPtr cr, ref double x, ref double y);
142 [DllImport (CairoImp)]
143 public static extern void cairo_inverse_transform_distance (IntPtr cr, ref double dx, ref double dy);
148 [DllImport (CairoImp)]
149 public static extern void cairo_new_path (IntPtr cr);
151 [DllImport (CairoImp)]
152 public static extern void cairo_move_to (IntPtr cr, double x, double y);
154 [DllImport (CairoImp)]
155 public static extern void cairo_line_to (IntPtr cr, double x, double y);
157 [DllImport (CairoImp)]
158 public static extern void cairo_curve_to (
159 IntPtr cr, double x1, double y1, double x2, double y2, double x3, double y3);
161 [DllImport (CairoImp)]
162 public static extern void cairo_arc (
163 IntPtr cr, double xc, double yc, double radius, double angel1, double angel2);
165 [DllImport (CairoImp)]
166 public static extern void cairo_arc_negative (
167 IntPtr cr, double xc, double yc, double radius, double angel1, double angel2);
169 [DllImport (CairoImp)]
170 public static extern void cairo_rel_move_to (IntPtr cr, double dx, double dy);
172 [DllImport (CairoImp)]
173 public static extern void cairo_rel_line_to (IntPtr cr, double dx, double dy);
175 [DllImport (CairoImp)]
176 public static extern void cairo_rel_curve_to (
177 IntPtr cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
179 [DllImport (CairoImp)]
180 public static extern void cairo_rectangle (IntPtr cr, double x, double y, double width, double height);
182 [DllImport (CairoImp)]
183 public static extern void cairo_close_path (IntPtr cr);
188 [DllImport (CairoImp)]
189 public static extern void cairo_stroke (IntPtr cr);
191 [DllImport (CairoImp)]
192 public static extern void cairo_fill (IntPtr cr);
194 [DllImport (CairoImp)]
195 public static extern void cairo_clip (IntPtr cr);
200 [DllImport (CairoImp)]
201 public static extern void cairo_select_font (IntPtr cr, string key, FontSlant slant, FontWeight weight);
203 [DllImport (CairoImp)]
204 public static extern void cairo_scale_font (IntPtr cr, double scale);
206 [DllImport (CairoImp)]
207 public static extern void cairo_transform_font (IntPtr cr, IntPtr matrix);
209 [DllImport (CairoImp)]
210 public static extern void cairo_show_text (IntPtr cr, string utf8);
212 [DllImport (CairoImp)]
213 public static extern void cairo_font_set_transform (IntPtr font, IntPtr matrix);
215 [DllImport (CairoImp)]
216 public static extern void cairo_font_current_transform (IntPtr font, IntPtr matrix);
218 [DllImport (CairoImp)]
219 public static extern void cairo_font_reference (IntPtr font);
221 [DllImport (CairoImp)]
222 public static extern void cairo_font_destroy (IntPtr font);
224 [DllImport (CairoImp)]
225 public static extern void cairo_current_font_extents (IntPtr source, ref Extents extents);
227 [DllImport (CairoImp)]
228 public static extern void cairo_show_glyphs (IntPtr ct, IntPtr glyphs, int num_glyphs);
230 [DllImport (CairoImp)]
231 public static extern void cairo_text_path (IntPtr ct, string utf8);
233 [DllImport (CairoImp)]
234 public static extern void cairo_glyph_path (IntPtr ct, IntPtr glyphs, int num_glyphs);
237 // Cairo's font manipulation platform-specific Unix Fontconfig/Freetype interface
239 [DllImport (CairoImp)]
240 public static extern IntPtr cairo_ft_font_create (IntPtr ft_library, IntPtr ft_pattern);
246 [DllImport (CairoImp)]
247 public static extern void cairo_show_surface (IntPtr cr, IntPtr surface, int width, int height);
254 [DllImport (CairoImp)]
255 public static extern Cairo.Operator cairo_current_operator (IntPtr cr);
257 [DllImport (CairoImp)]
258 public static extern void cairo_current_rgb_color (
259 IntPtr cr, out double red, out double green, out double blue);
261 [DllImport (CairoImp)]
262 public static extern double cairo_current_alpha (IntPtr cr);
264 [DllImport (CairoImp)]
265 public static extern double cairo_current_tolerance (IntPtr cr);
267 [DllImport (CairoImp)]
268 public static extern void cairo_current_point (
269 IntPtr cr, out double x, out double y);
271 [DllImport (CairoImp)]
272 public static extern Cairo.FillRule cairo_current_fill_rule (IntPtr cr);
274 [DllImport (CairoImp)]
275 public static extern double cairo_current_line_width (IntPtr cr);
277 [DllImport (CairoImp)]
278 public static extern LineCap cairo_current_line_cap (IntPtr cr);
280 [DllImport (CairoImp)]
281 public static extern LineJoin cairo_current_line_join (IntPtr cr);
283 [DllImport (CairoImp)]
284 public static extern double cairo_current_miter_limit (IntPtr cr);
286 [DllImport (CairoImp)]
287 public static extern void cairo_current_matrix (IntPtr cr, IntPtr matrix);
289 [DllImport (CairoImp)]
290 public static extern IntPtr cairo_current_target_surface (IntPtr cr);
293 // Error status queries
295 [DllImport (CairoImp)]
296 public static extern Cairo.Status cairo_status (IntPtr cr);
298 [DllImport (CairoImp, EntryPoint="cairo_status_string")]
299 static extern IntPtr _cairo_status_string (IntPtr cr);
301 public static string cairo_status_string (IntPtr cr)
303 return Marshal.PtrToStringAnsi (_cairo_status_string (cr));
307 // Surface Manipulation
310 [DllImport (CairoImp)]
311 public static extern IntPtr cairo_surface_create_for_image (
312 string data, Cairo.Format format, int width, int height, int stride);
314 [DllImport (CairoImp)]
315 public static extern IntPtr cairo_image_surface_create (Cairo.Format format, int width,
319 [DllImport (CairoImp)]
320 public static extern IntPtr cairo_surface_create_similar (
321 IntPtr surface, Cairo.Format format, int width, int height);
323 [DllImport (CairoImp)]
324 public static extern IntPtr cairo_surface_create_similar_solid (
325 IntPtr surface, Cairo.Format format,
326 int width, int height, double red, double green, double blue, double alpha);
328 [DllImport (CairoImp)]
329 public static extern void cairo_surface_reference (IntPtr surface);
331 [DllImport (CairoImp)]
332 public static extern void cairo_surface_destroy (IntPtr surface);
334 [DllImport (CairoImp)]
335 public static extern Cairo.Status cairo_surface_set_repeat (
336 IntPtr surface, int repeat);
338 [DllImport (CairoImp)]
339 public static extern Cairo.Status cairo_surface_set_matrix (
340 IntPtr surface, IntPtr matrix);
342 [DllImport (CairoImp)]
343 public static extern Cairo.Status cairo_surface_get_matrix (
344 IntPtr surface, out IntPtr matrix);
346 [DllImport (CairoImp)]
347 public static extern Cairo.Status cairo_surface_set_filter (
348 IntPtr surface, Cairo.Filter filter);
354 [DllImport (CairoImp)]
355 public static extern IntPtr cairo_matrix_create ();
357 [DllImport (CairoImp)]
358 public static extern void cairo_matrix_destroy (IntPtr matrix);
360 [DllImport (CairoImp)]
361 public static extern Cairo.Status cairo_matrix_copy (
362 IntPtr matrix, out IntPtr other);
364 [DllImport (CairoImp)]
365 public static extern Cairo.Status cairo_matrix_set_identity (IntPtr matrix);
367 [DllImport (CairoImp)]
368 public static extern Cairo.Status cairo_matrix_set_affine (
370 double a, double b, double c, double d, double tx, double ty);
372 [DllImport (CairoImp)]
373 public static extern Cairo.Status cairo_matrix_get_affine (
375 out double a, out double b, out double c,
376 out double d, out double tx, out double ty);
378 [DllImport (CairoImp)]
379 public static extern Cairo.Status cairo_matrix_translate (
380 IntPtr matrix, double tx, double ty);
382 [DllImport (CairoImp)]
383 public static extern Cairo.Status cairo_matrix_scale (
384 IntPtr matrix, double sx, double sy);
386 [DllImport (CairoImp)]
387 public static extern Cairo.Status cairo_matrix_rotate (
388 IntPtr matrix, double radians);
390 [DllImport (CairoImp)]
391 public static extern Cairo.Status cairo_matrix_invert (IntPtr matrix);
393 [DllImport (CairoImp)]
394 public static extern Cairo.Status cairo_matrix_multiply (
395 out IntPtr result, IntPtr a, IntPtr b);
397 [DllImport (CairoImp)]
398 public static extern Cairo.Status cairo_matrix_transform_distance (
399 IntPtr matrix, ref double dx, ref double dy);
401 [DllImport (CairoImp)]
402 public static extern Cairo.Status cairo_matrix_transform_point (
403 IntPtr matrix, ref double x, ref double y);
405 [DllImport (CairoImp)]
406 public static extern void cairo_set_font (IntPtr ct, IntPtr font);
408 [DllImport (CairoImp)]
409 public static extern IntPtr cairo_current_font (IntPtr ct);
414 [DllImport (CairoImp)]
415 public static extern IntPtr cairo_pattern_create_for_surface (IntPtr surface);
417 [DllImport (CairoImp)]
418 public static extern IntPtr cairo_pattern_create_linear (double x0, double y0,
419 double x1, double y1);
421 [DllImport (CairoImp)]
422 public static extern IntPtr cairo_pattern_create_radial (double cx0, double cy0,
423 double radius0, double cx1, double cy1, double radius1);
425 [DllImport (CairoImp)]
426 public static extern void cairo_pattern_reference (IntPtr pattern);
428 [DllImport (CairoImp)]
429 public static extern void cairo_pattern_destroy (IntPtr pattern);
431 [DllImport (CairoImp)]
432 public static extern Status cairo_pattern_add_color_stop (IntPtr pattern,
433 double offset, double red, double green, double blue, double alpha);
435 [DllImport (CairoImp)]
436 public static extern Status cairo_pattern_set_matrix (IntPtr pattern, IntPtr matrix);
438 [DllImport (CairoImp)]
439 public static extern Status cairo_pattern_get_matrix (IntPtr pattern, out IntPtr matrix);
441 [DllImport (CairoImp)]
442 public static extern Status cairo_pattern_set_extend (IntPtr pattern, Extend extend);
444 [DllImport (CairoImp)]
445 public static extern Extend cairo_pattern_get_extend (IntPtr pattern);
447 [DllImport (CairoImp)]
448 public static extern Status cairo_pattern_set_filter (IntPtr pattern, Filter filter);
450 [DllImport (CairoImp)]
451 public static extern Filter cairo_pattern_get_filter (IntPtr pattern);
456 // Freetype interface need it by cairo_ft interface calls
458 public class FreeType
460 internal const string FreeTypeImp = "freetype";
462 [DllImport (FreeTypeImp)]
463 public static extern int FT_Init_FreeType (out IntPtr library);
465 [DllImport (FreeTypeImp)]
466 public static extern int FT_Set_Char_Size (IntPtr face, long width, long height, uint horz_res, uint vert_res);
470 // Fontconfig interface need it by cairo_ft interface calls
472 public class FontConfig
474 internal const string FontConfigImp = "fontconfig";
476 public const string FC_FAMILY = "family";
477 public const string FC_STYLE = "style";
478 public const string FC_SLANT = "slant";
479 public const string FC_WEIGHT = "weight";
481 [DllImport (FontConfigImp)]
482 public static extern bool FcPatternAddString (IntPtr pattern, string obj, string value);
484 [DllImport (FontConfigImp)]
485 public static extern bool FcPatternAddInteger (IntPtr pattern, string obj, int value);
487 [DllImport (FontConfigImp)]
488 public static extern IntPtr FcPatternCreate ();
490 [DllImport (FontConfigImp)]
491 public static extern bool FcPatternDestroy (IntPtr pattern);
506 public enum Operator {
526 DisjointOverReverse = 20,
528 DisjointInReverse = 22,
530 DisjointOutReverse = 24,
532 DisjointAtopReverse = 26,
539 ConjointOverReverse = 36,
541 ConjointInReverse = 38,
543 ConjointOutReverse = 40,
545 ConjointAtopReverse = 42,
549 public enum FillRule {
554 public enum LineCap {
558 public enum LineJoin {
580 public enum FontSlant {
586 public enum FontWeight {
598 [StructLayout(LayoutKind.Sequential)]
599 public struct Extents
601 public double x_bearing;
602 public double y_bearing;
604 public double height;
605 public double x_advance;
606 public double y_advance;
609 [StructLayout(LayoutKind.Sequential)]