fill_preserve


Description:

public void fill_preserve ()

Example: Fill preserve:

public static int main (string[] args) {
// Create a context:
Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 256, 256);
Cairo.Context context = new Cairo.Context (surface);

// The content:
context.move_to (128.0, 25.6);
context.line_to (230.4, 230.4);
context.rel_line_to (-102.4, 0.0);
context.curve_to (51.2, 230.4, 51.2, 128.0, 128.0, 128.0);
context.close_path ();

context.move_to (64.0, 25.6);
context.rel_line_to (51.2, 51.2);
context.rel_line_to (-51.2, 51.2);
context.rel_line_to (-51.2, -51.2);
context.close_path ();

context.set_line_width (10.0);
context.set_source_rgb (0, 0, 1);
context.fill_preserve ();
context.set_source_rgb (0, 0, 0);
context.stroke ();

// Save the image:
surface.write_to_png ("img.png");

return 0;
}

valac --pkg cairo fill-preserve.vala

Example: Fill rules:

public static int main (string[] args) {
// Create a context:
Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 256, 256);
Cairo.Context context = new Cairo.Context (surface);

context.set_line_width (6);

// First part:
context.rectangle (12, 12, 232, 70);
context.new_sub_path ();
context.arc (64, 64, 40, 0, 2*Math.PI);
context.new_sub_path ();
context.arc_negative (192, 64, 40, 0, -2*Math.PI);

context.set_fill_rule (Cairo.FillRule.EVEN_ODD);
context.set_source_rgb (0, 0.7, 0);
context.fill_preserve ();
context.set_source_rgb (0, 0, 0);
context.stroke ();

// Second part:
context.translate (0, 128);
context.rectangle (12, 12, 232, 70);
context.new_sub_path ();
context.arc (64, 64, 40, 0, 2*Math.PI);
context.new_sub_path ();
context.arc_negative (192, 64, 40, 0, -2*Math.PI);

context.set_fill_rule (Cairo.FillRule.WINDING);
context.set_source_rgb (0, 0, 0.9);
context.fill_preserve ();
context.set_source_rgb (0, 0, 0);
context.stroke ();

// Save the image:
surface.write_to_png ("img.png");

return 0;
}

valac --pkg cairo fill-rule.vala