Beispiel #1
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;

    cairo_test_paint_checkered (cr);

    cairo_translate (cr, PAD, PAD);

    pattern = cairo_pattern_create_mesh ();

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern, 0, 0);
    cairo_mesh_pattern_curve_to (pattern,  30, -30, 60,  30, 100, 0);
    cairo_mesh_pattern_curve_to (pattern, 130, 140, 60, -40, 100, 100);
    cairo_mesh_pattern_curve_to (pattern,  60,  70, 30, 130,   0, 100);
    cairo_mesh_pattern_curve_to (pattern, -30, -40, 30, 140,   0, 0);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_set_source (cr, pattern);
    cairo_paint (cr);
    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;

    cairo_test_paint_checkered (cr);

    cairo_translate (cr, PAD, PAD);

    pattern = cairo_pattern_create_mesh ();

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern, 0, 0);
    cairo_mesh_pattern_curve_to (pattern, 30, -30,  60,  30, 100, 0);
    cairo_mesh_pattern_curve_to (pattern, 60,  30, 130,  60, 100, 100);
    cairo_mesh_pattern_curve_to (pattern, 60,  70,  30, 130,   0, 100);
    cairo_mesh_pattern_curve_to (pattern, 30,  70, -30,  30,   0, 0);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern, 50, 50);
    cairo_mesh_pattern_curve_to (pattern, 80, 20, 110, 80, 150, 50);

    cairo_mesh_pattern_curve_to (pattern, 110, 80, 180, 110, 150, 150);

    cairo_mesh_pattern_curve_to (pattern, 110, 120, 80, 180, 50, 150);

    cairo_mesh_pattern_curve_to (pattern, 80, 120, 20, 80, 50, 50);

    cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, 1, 0, 0, 0.3);
    cairo_mesh_pattern_set_corner_color_rgb  (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, 0, 0, 1, 0.3);
    cairo_mesh_pattern_set_corner_color_rgb  (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_scale (cr, .5, .5);

    cairo_set_source (cr, pattern);
    cairo_paint (cr);

    cairo_translate (cr, PAT_WIDTH, PAT_HEIGHT);
    cairo_translate (cr, PAT_WIDTH/2, PAT_HEIGHT/2);
    cairo_rotate (cr, M_PI/4);
    cairo_translate (cr, -PAT_WIDTH, -PAT_HEIGHT);
    cairo_set_source (cr, pattern);
    cairo_paint (cr);

    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #3
0
/* Cairo::MeshPattern */
static VALUE
cr_mesh_pattern_initialize (VALUE self)
{
  cairo_pattern_t *pattern;

  pattern = cairo_pattern_create_mesh ();
  cr_pattern_check_status (pattern);
  DATA_PTR (self) = pattern;
  return Qnil;
}
Beispiel #4
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    double offset;

    cairo_test_paint_checkered (cr);

    pattern = cairo_pattern_create_mesh ();

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern, 0, 0);
    cairo_mesh_pattern_line_to (pattern, 1, 0);
    cairo_mesh_pattern_line_to (pattern, 1, 1);
    cairo_mesh_pattern_line_to (pattern, 0, 1);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 0, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 1, 1, 1);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 1);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_mesh_pattern_begin_patch (pattern);

    /* A small 1x1 red patch, that should be rendered as a 2x2 red
     * square in the center of the image */

    offset = 0.5 / SIZE;

    cairo_mesh_pattern_move_to (pattern, 0.5 + offset, 0.5 + offset);
    cairo_mesh_pattern_line_to (pattern, 0.5 + offset, 0.5 - offset);
    cairo_mesh_pattern_line_to (pattern, 0.5 - offset, 0.5 - offset);
    cairo_mesh_pattern_line_to (pattern, 0.5 - offset, 0.5 + offset);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 0, 0);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_scale (cr, SIZE, SIZE);

    cairo_set_source (cr, pattern);
    cairo_paint (cr);
    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #5
0
static cairo_pattern_t *
mesh (void)
{
    cairo_pattern_t *pattern;

    pattern = cairo_pattern_create_mesh ();

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern, 0, 0);
    cairo_mesh_pattern_curve_to (pattern, 30, -30,  60,  30, 100, 0);
    cairo_mesh_pattern_curve_to (pattern, 60,  30, 130,  60, 100, 100);
    cairo_mesh_pattern_curve_to (pattern, 60,  70,  30, 130,   0, 100);
    cairo_mesh_pattern_curve_to (pattern, 30,  70, -30,  30,   0, 0);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern, 50, 50);
    cairo_mesh_pattern_curve_to (pattern,  80,  20, 110,  80, 150, 50);
    cairo_mesh_pattern_curve_to (pattern, 110,  80, 180, 110, 150, 150);
    cairo_mesh_pattern_curve_to (pattern, 110, 120,  80, 180,  50, 150);
    cairo_mesh_pattern_curve_to (pattern,  80, 120,  20,  80,  50, 50);

    cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, 1, 0, 0, 0.3);
    cairo_mesh_pattern_set_corner_color_rgb  (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, 0, 0, 1, 0.3);
    cairo_mesh_pattern_set_corner_color_rgb  (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_end_patch (pattern);

    return pattern;
}
Beispiel #6
0
int main(int argc, char **argv)
{
    cairo_surface_t *surface;
    cairo_pattern_t *pattern;
    cairo_t *cr;

    pattern = cairo_pattern_create_mesh ();
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256, 256);
    cr = cairo_create (surface);

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    patch_rect (pattern, 10, 15, 50, 70, 8, 0, 0, 0, 1);

    cairo_set_source (cr, pattern);
    cairo_paint (cr);

    cairo_destroy (cr);

    cairo_surface_write_to_png (surface, "blur.png");

    return 0;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    unsigned int i, j;
    unsigned int num_patches;
    double x, y;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    cairo_translate (cr, PAD, PAD);

    pattern = cairo_pattern_create_mesh ();
    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern,    0,    0);
    cairo_mesh_pattern_line_to (pattern, SIZE,    0);
    cairo_mesh_pattern_line_to (pattern, SIZE, SIZE);
    cairo_mesh_pattern_line_to (pattern,    0, SIZE);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_set_control_point (pattern, 0, SIZE * .7, SIZE * .7);
    cairo_mesh_pattern_set_control_point (pattern, 1, SIZE * .9, SIZE * .7);
    cairo_mesh_pattern_set_control_point (pattern, 2, SIZE * .9, SIZE * .9);
    cairo_mesh_pattern_set_control_point (pattern, 3, SIZE * .7, SIZE * .9);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern,   SIZE + PAD,    0);
    cairo_mesh_pattern_line_to (pattern, 2*SIZE + PAD,    0);
    cairo_mesh_pattern_line_to (pattern, 2*SIZE + PAD, SIZE);
    cairo_mesh_pattern_line_to (pattern,   SIZE + PAD, SIZE);

    cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1);
    cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_set_source (cr, pattern);
    cairo_paint (cr);

    /* mark the location of the control points */
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_mesh_pattern_get_patch_count (pattern, &num_patches);
    for (i = 0; i < num_patches; i++) {
	for (j = 0; j < 4; j++) {
	    cairo_mesh_pattern_get_control_point (pattern, i, j, &x, &y);
	    cairo_rectangle (cr, x - 5, y - 5, 10, 10);
	    cairo_fill (cr);
	}
    }

    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}