示例#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_surface_t *surface;
    uint32_t data[16] = {
	0x80808080, 0x80808080,		0x80800000, 0x80800000,
	0x80808080, 0x80808080,		0x80800000, 0x80800000,

	0x80008000, 0x80008000,		0x80000080, 0x80000080,
	0x80008000, 0x80008000,		0x80000080, 0x80000080
    };

    surface = cairo_image_surface_create_for_data ((unsigned char *) data,
						   CAIRO_FORMAT_ARGB32, 4, 4, 16);

    cairo_test_paint_checkered (cr);

    cairo_scale (cr, 4, 4);

    cairo_set_source_surface (cr, surface, 2 , 2);
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
    cairo_paint (cr);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
示例#3
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    int i, j, k;
    cairo_extend_t extend[NUM_EXTEND] = {
	CAIRO_EXTEND_NONE,
	CAIRO_EXTEND_REPEAT,
	CAIRO_EXTEND_REFLECT,
	CAIRO_EXTEND_PAD
    };

    cairo_test_paint_checkered (cr);

    for (j = 0; j < NUM_EXTEND; j++) {
	for (i = 0; i < NUM_GRADIENTS; i++) {
	    double r1_offset = i % 2 ? SIZE / 12.0 : 0.0;
	    double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0;
	    for (k = 0; k < NUM_GRADIENTS; k++) {
		double r2_offset = k % 2 ? SIZE / 12.0 : 0.0;
		double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.;
		draw_gradient (cr,
			       i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE,
			       r1_offset, r1_radius,
			       r2_offset, r2_radius,
			       extend[j]);
	    }
	}
    }

    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;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    unsigned int i, j;

    cairo_extend_t extend[NUM_EXTEND] = {
        CAIRO_EXTEND_NONE,
        CAIRO_EXTEND_REPEAT,
        CAIRO_EXTEND_REFLECT,
        CAIRO_EXTEND_PAD
    };

    cairo_test_paint_checkered (cr);

    pattern = cairo_pattern_create_linear (0, 2*PAD, 0, HEIGHT - 2*PAD);

    cairo_pattern_add_color_stop_rgb (pattern, 0, 0, 0, 1);
    cairo_pattern_add_color_stop_rgb (pattern, 1, 0, 0, 1);

    cairo_translate (cr, PAD, PAD);

    for (i = 0; i < 2; i++) {
        cairo_save (cr);

        for (j = 0; j < NUM_EXTEND; j++) {
            cairo_pattern_set_extend (pattern, extend[j]);

            cairo_reset_clip (cr);
            cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
            cairo_clip (cr);

            if (i & 1) {
                cairo_set_source_rgb (cr, 0, 1, 0);
                cairo_mask (cr, pattern);
            } else {
                cairo_set_source (cr, pattern);
                cairo_paint (cr);
            }

            cairo_translate (cr, WIDTH+PAD, 0);
        }

        cairo_restore (cr);
        cairo_translate (cr, 0, HEIGHT+PAD);
    }

    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
示例#6
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;
}
示例#7
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surface;
    cairo_surface_t *image;
    cairo_surface_t *subimage;
    cairo_rectangle_int_t extents;
    cairo_t *cr2;

    extents.x = extents.y = 10;
    extents.width = WIDTH - 20;
    extents.height = HEIGHT - 20;

    /* We use a similar surface to have way smaller ref images */
    surface = cairo_surface_create_similar (cairo_get_target (cr),
					    CAIRO_CONTENT_COLOR_ALPHA,
					    WIDTH, HEIGHT);

    /* First we have to defeat xcb's deferred clear */
    cr2 = cairo_create (surface);
    cairo_test_paint_checkered (cr2);
    cairo_destroy (cr2);

    /* Get us an image surface with a non-natural stride */
    image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					WIDTH, HEIGHT);
    subimage = cairo_surface_map_to_image (image, &extents);

    /* Paint the subimage to the similar surface and trigger the big upload */
    cr2 = cairo_create (surface);
    cairo_set_source_surface (cr2, subimage, 0, 0);
    cairo_paint (cr2);
    cairo_destroy (cr2);

    /* Finally we make sure that errors aren't lost. */
    cairo_surface_unmap_image (image, subimage);
    cairo_set_source_surface (cr, surface, 0, 0);
    cairo_paint (cr);
    cairo_surface_destroy (image);
    cairo_surface_destroy (surface);

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

    blue = cairo_pattern_create_rgba (0.0, 0.0, 1.0, 0.8);
    red = cairo_pattern_create_rgba (1.0, 0.0, 0.0, 0.2);

    cairo_test_paint_checkered (cr);

    fill_and_stroke (cr, rectangle, blue, red);

    cairo_translate (cr, SIZE + 2 * PAD, 0);

    fill_and_stroke (cr, circle, red, blue);

    cairo_pattern_destroy (blue);
    cairo_pattern_destroy (red);

    return CAIRO_TEST_SUCCESS;
}
示例#9
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    /* First draw a checkered background */
    cairo_test_paint_checkered (cr);

    /* Then draw the original caps-joins test but with a bit of alphs thrown in. */
    cairo_set_line_width (cr, LINE_WIDTH);

    cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5); /* 50% red */
    cairo_translate (cr, PAD, PAD);

    make_path (cr);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
    cairo_stroke (cr);

    cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 0.5); /* 50% green */
    cairo_translate (cr, SIZE + PAD, 0.);

    make_path (cr);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
    cairo_stroke (cr);

    cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.5); /* 50% blue */

    cairo_translate (cr, SIZE + PAD, 0.);

    make_path (cr);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}