clip-device-offset.c [plain text]
#include "cairo-test.h"
#define WIDTH 50
#define HEIGHT 50
static cairo_pattern_t *
create_green_source (void)
{
cairo_surface_t *image;
cairo_pattern_t *pattern;
cairo_t *cr;
image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT);
cr = cairo_create (image);
cairo_surface_destroy (image);
cairo_set_source_rgb (cr, 0, 1, 0);
cairo_paint (cr);
pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
cairo_destroy (cr);
return pattern;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_pattern_t *source;
double old_x, old_y;
cairo_surface_get_device_offset (cairo_get_target (cr), &old_x, &old_y);
cairo_surface_set_device_offset (cairo_get_target (cr), old_x+5, old_y+5);
source = create_green_source ();
cairo_set_source (cr, source);
cairo_pattern_destroy (source);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
cairo_clip (cr);
cairo_paint (cr);
cairo_surface_set_device_offset (cairo_get_target (cr), old_x, old_y);
return CAIRO_TEST_SUCCESS;
}
CAIRO_TEST (clip_device_offset,
"Test clipping on surfaces with device offsets",
"clip",
NULL,
WIDTH+10, HEIGHT+10,
NULL, draw)