3 * Copyright (C) 2006-2009 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
23 [CCode (cheader_filename = "cairo.h", gir_namespace = "cairo", gir_version = "1.0")]
26 [CCode (ref_function = "cairo_reference", unref_function = "cairo_destroy", cname = "cairo_t", cprefix = "cairo_", cheader_filename = "cairo.h")]
27 public class Context {
28 [CCode (cname = "cairo_create")]
29 public Context (Surface target);
30 public Status status ();
32 public void restore ();
34 public unowned Surface get_target ();
35 public void push_group ();
36 public void push_group_with_content (Content content);
37 public Pattern pop_group ();
38 public void pop_group_to_source ();
39 public unowned Surface get_group_target ();
41 public void set_source_rgb (double red, double green, double blue);
42 public void set_source_rgba (double red, double green, double blue, double alpha);
43 public void set_source (Pattern source);
44 public void set_source_surface (Surface surface, double x, double y);
45 public unowned Pattern get_source ();
47 public void set_matrix (Matrix matrix);
48 public void get_matrix (out Matrix matrix);
50 public void set_antialias (Antialias antialias);
51 public Antialias get_antialias ();
53 public void set_dash (double[]? dashes, double offset);
55 public void set_fill_rule (FillRule fill_rule);
56 public FillRule get_fill_rule ();
58 public void set_line_cap (LineCap line_cap);
59 public LineCap get_line_cap ();
61 public void set_line_join (LineJoin line_join);
62 public LineJoin get_line_join ();
64 public void set_line_width (double width);
65 public double get_line_width ();
67 public void set_miter_limit (double limit);
68 public double get_miter_limit ();
70 public void set_operator (Operator op);
71 public Operator get_operator ();
73 public void set_tolerance (double tolerance);
74 public double get_tolerance ();
77 public void clip_preserve ();
78 public void clip_extents (out double x1, out double y1, out double x2, out double y2);
79 public void reset_clip ();
82 public void fill_preserve ();
83 public void fill_extents (out double x1, out double y1, out double x2, out double y2);
84 public bool in_fill (double x, double y);
86 public void mask (Pattern pattern);
87 public void mask_surface (Surface surface, double surface_x, double surface_y);
90 public void paint_with_alpha (double alpha);
92 public void stroke ();
93 public void stroke_preserve ();
94 public void stroke_extents (out double x1, out double y1, out double x2, out double y2);
95 public bool in_stroke (double x, double y);
97 public void copy_page ();
98 public void show_page ();
100 public Path copy_path ();
101 public Path copy_path_flat ();
103 public void append_path (Path path);
105 public void get_current_point (out double x, out double y);
107 public void new_path ();
108 public void new_sub_path ();
109 public void close_path ();
111 public void arc (double xc, double yc, double radius, double angle1, double angle2);
112 public void arc_negative (double xc, double yc, double radius, double angle1, double angle2);
114 public void curve_to (double x1, double y1, double x2, double y2, double x3, double y3);
115 public void line_to (double x, double y);
116 public void move_to (double x, double y);
118 public void rectangle (double x, double y, double width, double height);
120 public void glyph_path (Glyph[] glyphs);
121 public void text_path (string utf8);
123 public void rel_curve_to (double dx1, double dy1, double dx2, double dy2, double dx3, double dy3);
124 public void rel_line_to (double dx, double dy);
125 public void rel_move_to (double dx, double dy);
127 public void translate (double tx, double ty);
128 public void scale (double sx, double sy);
129 public void rotate (double angle);
130 public void transform (Matrix matrix);
131 public void identity_matrix ();
133 public void user_to_device (ref double x, ref double y);
134 public void user_to_device_distance (ref double dx, ref double dy);
135 public void device_to_user (ref double x, ref double y);
136 public void device_to_user_distance (ref double dx, ref double dy);
138 public void select_font_face (string family, FontSlant slant, FontWeight weight);
139 public void set_font_size (double size);
140 public void set_font_matrix (Matrix matrix);
141 public void get_font_matrix (out Matrix matrix);
142 public void set_font_options (FontOptions options);
143 public void get_font_options (out FontOptions options);
145 public void show_text (string utf8);
146 public void show_glyphs (Glyph[] glyphs);
148 public unowned FontFace get_font_face ();
149 public void font_extents (out FontExtents extents);
150 public void set_font_face (FontFace font_face);
151 public void set_scaled_font (ScaledFont font);
152 public void text_extents (string utf8, out TextExtents extents);
153 public void glyph_extents (Glyph[] glyphs, out TextExtents extents);
156 [CCode (cname = "cairo_antialias_t")]
157 public enum Antialias {
164 [CCode (cname = "cairo_fill_rule_t")]
165 public enum FillRule {
170 [CCode (cname = "cairo_line_cap_t")]
171 public enum LineCap {
177 [CCode (cname = "cairo_line_join_t")]
178 public enum LineJoin {
184 [CCode (cname = "cairo_operator_t")]
185 public enum Operator {
203 [CCode (free_function = "cairo_path_destroy", cname = "cairo_path_t")]
205 public Status status;
206 [CCode (array_length = false)]
207 public PathData[] data;
211 [CCode (cname = "cairo_path_data_t")]
212 public struct PathData {
213 public PathDataHeader header;
214 public PathDataPoint point;
217 public struct PathDataHeader {
218 public PathDataType type;
222 public struct PathDataPoint {
227 [CCode (cprefix = "CAIRO_PATH_", cname = "cairo_path_data_type_t")]
228 public enum PathDataType {
236 [CCode (ref_function = "cairo_pattern_reference", unref_function = "cairo_pattern_destroy", cname = "cairo_pattern_t")]
237 public class Pattern {
238 public void add_color_stop_rgb (double offset, double red, double green, double blue);
239 public void add_color_stop_rgba (double offset, double red, double green, double blue, double alpha);
241 [CCode (cname = "cairo_pattern_create_rgb")]
242 public Pattern.rgb (double red, double green, double blue);
243 [CCode (cname = "cairo_pattern_create_rgba")]
244 public Pattern.rgba (double red, double green, double blue, double alpha);
245 [CCode (cname = "cairo_pattern_create_for_surface")]
246 public Pattern.for_surface (Surface surface);
247 [CCode (cname = "cairo_pattern_create_linear")]
248 public Pattern.linear (double x0, double y0, double x1, double y1);
249 [CCode (cname = "cairo_pattern_create_radial")]
250 public Pattern.radial (double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
252 public Status status ();
254 public void set_extend (Extend extend);
255 public Extend get_extend ();
257 public void set_filter (Filter filter);
258 public Filter get_filter ();
260 public void set_matrix (Matrix matrix);
261 public void get_matrix (out Matrix matrix);
263 public PatternType get_type ();
266 [CCode (cname = "cairo_extend_t")]
274 [CCode (cname = "cairo_filter_t")]
284 [CCode (cname = "cairo_pattern_type_t")]
285 public enum PatternType {
293 [CCode (ref_function = "cairo_region_reference", unref_function = "cairo_region_destroy", cname = "cairo_region_t")]
294 public class Region {
295 [CCode (cname = "cairo_region_create")]
297 [CCode (cname = "cairo_region_create_rectangle")]
298 public Region.rectangle (RectangleInt rectangle);
299 [CCode (cname = "cairo_region_create_rectangles")]
300 public Region.rectangles (RectangleInt[] rects);
301 public Status status ();
302 public RectangleInt get_extents ();
303 public int num_rectangles ();
304 public RectangleInt get_rectangle (int nth);
305 public bool is_empty ();
306 public bool contains_point (int x, int y);
307 public RegionOverlap contains_rectangle (RectangleInt rectangle);
308 public bool equal (Region other);
309 public void translate (int dx, int dy);
310 public Status intersect (Region other);
311 public Status intersect_rectangle (RectangleInt rectangle);
312 public Status subtract (Region other);
313 public Status subtract_rectangle (RectangleInt rectangle);
314 public Status union (Region other);
315 public Status union_rectangle (RectangleInt rectangle);
316 public Status xor (Region other);
317 public Status xor_rectangle (RectangleInt rectangle);
320 [CCode (cname = "cairo_region_overlap_t")]
321 public enum RegionOverlap {
327 [CCode (cname = "cairo_glyph_t")]
331 [CCode (cname = "cairo_font_slant_t")]
332 public enum FontSlant {
338 [CCode (cname = "cairo_font_weight_t")]
339 public enum FontWeight {
345 [CCode (ref_function = "cairo_font_face_reference", unref_function = "cairo_font_face_destroy", cname = "cairo_font_face_t")]
346 public class FontFace {
347 public Status status ();
348 public FontType get_type ();
351 [CCode (cname = "cairo_font_type_t")]
352 public enum FontType {
360 [CCode (ref_function = "cairo_scaled_font_reference", unref_function = "cairo_scaled_font_destroy", cname = "cairo_scaled_font_t")]
361 public class ScaledFont {
362 [CCode (cname = "cairo_scaled_font_create")]
363 public ScaledFont (FontFace font_face, Matrix font_matrix, Matrix ctm, FontOptions options);
364 public Status status ();
365 public void extents (out FontExtents extents);
366 public void text_extents (string utf8, out TextExtents extents);
367 public void glyph_extents (Glyph[] glyphs, out TextExtents extents);
368 public unowned FontFace get_font_face ();
369 public void get_font_options (out FontOptions options);
370 public void get_font_matrix (out Matrix font_matrix);
371 public void get_ctm (out Matrix ctm);
372 public FontType get_type ();
375 [CCode (cname = "cairo_font_extents_t")]
376 public struct FontExtents {
377 public double ascent;
378 public double descent;
379 public double height;
380 public double max_x_advance;
381 public double max_y_advance;
384 [CCode (cname = "cairo_text_extents_t")]
385 public struct TextExtents {
386 public double x_bearing;
387 public double y_bearing;
389 public double height;
390 public double x_advance;
391 public double y_advance;
395 [CCode (copy_function = "cairo_font_options_copy", free_function = "cairo_font_options_destroy", cname = "cairo_font_options_t")]
396 public class FontOptions {
397 [CCode (cname = "cairo_font_options_create")]
398 public FontOptions ();
399 public Status status ();
400 public void merge (FontOptions other);
401 public ulong hash ();
402 public bool equal (FontOptions other);
403 public void set_antialias (Antialias antialias);
404 public Antialias get_antialias ();
405 public void set_subpixel_order (SubpixelOrder subpixel_order);
406 public SubpixelOrder get_subpixel_order ();
407 public void set_hint_style (HintStyle hint_style);
408 public HintStyle get_hint_style ();
409 public void set_hint_metrics (HintMetrics hint_metrics);
410 public HintMetrics get_hint_metrics ();
413 [CCode (cname = "cairo_subpixel_order_t")]
414 public enum SubpixelOrder {
422 [CCode (cname = "cairo_hint_style_t")]
423 public enum HintStyle {
431 [CCode (cname = "cairo_hint_metrics_t")]
432 public enum HintMetrics {
439 [CCode (ref_function = "cairo_surface_reference", unref_function = "cairo_surface_destroy", cname = "cairo_surface_t", cheader_filename = "cairo.h")]
440 public class Surface {
441 [CCode (cname = "cairo_surface_create_similar")]
442 public Surface.similar (Surface other, Content content, int width, int height);
443 public void finish ();
444 public void flush ();
445 public void get_font_options (out FontOptions options);
446 public Content get_content ();
447 public void mark_dirty ();
448 public void mark_dirty_rectangle (int x, int y, int width, int height);
449 public void set_device_offset (double x_offset, double y_offset);
450 public void get_device_offset (out double x_offset, out double y_offset);
451 public void set_fallback_resolution (double x_pixels_per_inch, double y_pixels_per_inch);
452 public Status status ();
453 public SurfaceType get_type ();
455 public Status write_to_png (string filename);
456 public Status write_to_png_stream (WriteFunc write_func);
459 [CCode (cname = "cairo_content_t")]
460 public enum Content {
466 [CCode (cname = "cairo_surface_type_t")]
467 public enum SurfaceType {
481 [CCode (cname = "cairo_format_t")]
491 [CCode (cname = "cairo_surface_t")]
492 public class ImageSurface : Surface {
493 [CCode (cname = "cairo_image_surface_create")]
494 public ImageSurface (Format format, int width, int height);
495 [CCode (cname = "cairo_image_surface_create_for_data")]
496 public ImageSurface.for_data ([CCode (array_length = false)] uchar[] data, Format format, int width, int height, int stride);
497 [CCode (array_length = false)]
498 public unowned uchar[] get_data ();
499 public Format get_format ();
500 public int get_width ();
501 public int get_height ();
502 public int get_stride ();
504 [CCode (cname = "cairo_image_surface_create_from_png")]
505 public ImageSurface.from_png (string filename);
506 [CCode (cname = "cairo_image_surface_create_from_png_stream")]
507 public ImageSurface.from_png_stream (ReadFunc read_func);
511 [CCode (cname = "cairo_surface_t", cheader_filename = "cairo-pdf.h")]
512 public class PdfSurface : Surface {
513 [CCode (cname = "cairo_pdf_surface_create")]
514 public PdfSurface (string filename, double width_in_points, double height_in_points);
515 [CCode (cname = "cairo_pdf_surface_create_for_stream")]
516 public PdfSurface.for_stream (WriteFunc write_func, double width_in_points, double height_in_points);
517 public void set_size (double width_in_points, double height_in_points);
520 [CCode (instance_pos = 0)]
521 public delegate Status ReadFunc (uchar[] data);
522 [CCode (instance_pos = 0)]
523 public delegate Status WriteFunc (uchar[] data);
526 [CCode (cname = "cairo_surface_t", cheader_filename = "cairo-ps.h")]
527 public class PsSurface : Surface {
528 [CCode (cname = "cairo_ps_surface_create")]
529 public PsSurface (string filename, double width_in_points, double height_in_points);
530 [CCode (cname = "cairo_ps_surface_create_for_stream")]
531 public PsSurface.for_stream (WriteFunc write_func, double width_in_points, double height_in_points);
532 public void set_size (double width_in_points, double height_in_points);
533 public void dsc_begin_setup ();
534 public void dsc_begin_page_setup ();
535 public void dsc_comment (string comment);
539 [CCode (cname = "cairo_surface_t", cheader_filename = "cairo-svg.h")]
540 public class SvgSurface : Surface {
541 [CCode (cname = "cairo_svg_surface_create")]
542 public SvgSurface (string filename, double width_in_points, double height_in_points);
543 [CCode (cname = "cairo_svg_surface_create_for_stream")]
544 public SvgSurface.for_stream (WriteFunc write_func, double width_in_points, double height_in_points);
545 public void restrict_to_version (SvgVersion version);
546 public static void get_versions (out SvgVersion[] versions);
549 [CCode (cname = "cairo_svg_version_t", cprefix = "CAIRO_SVG_")]
550 public enum SvgVersion {
556 [CCode (cname = "cairo_surface_t", cheader_filename = "cairo-xlib.h")]
557 public class XlibSurface : Surface {
558 [CCode (cname = "cairo_xlib_surface_create")]
559 public XlibSurface (void* dpy, int drawable, void* visual, int width, int height);
560 [CCode (cname = "cairo_xlib_surface_create_for_bitmap")]
561 public XlibSurface.for_bitmap (void* dpy, int bitmap, void* screen, int width, int height);
562 public void set_size (int width, int height);
563 public void* get_display ();
564 public void* get_screen ();
565 public void set_drawable (int drawable, int width, int height);
566 public int get_drawable ();
567 public void* get_visual ();
568 public int get_width ();
569 public int get_height ();
570 public int get_depth ();
573 [CCode (cname = "cairo_matrix_t", has_type_id = false)]
574 public struct Matrix {
575 [CCode (cname = "cairo_matrix_init")]
576 public Matrix (double xx, double yx, double xy, double yy, double x0, double y0);
577 [CCode (cname = "cairo_matrix_init_identity")]
578 public Matrix.identity ();
580 public void translate (double tx, double ty);
581 public void scale (double sx, double sy);
582 public void rotate (double radians);
583 public Status invert ();
584 public void multiply (Matrix a, Matrix b);
585 public void transform_distance (ref double dx, ref double dy);
586 public void transform_point (ref double x, ref double y);
596 [CCode (cname = "cairo_rectangle_t", has_type_id = false)]
597 public struct Rectangle {
601 public double height;
604 [CCode (cname = "cairo_rectangle_int_t", has_type_id = false)]
605 public struct RectangleInt {
612 [CCode (cname = "cairo_status_t")]
627 SURFACE_TYPE_MISMATCH,
628 PATTERN_TYPE_MISMATCH,
637 public int version ();
638 public unowned string version_string ();