static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_format_t format = CAIRO_FORMAT_ARGB32; cairo_t *cr_src; cairo_surface_t *png, *src; uint8_t *data; int stride; png = cairo_test_create_surface_from_png (ctx, png_filename); stride = cairo_format_stride_for_width (format, width) + 12; data = xcalloc (stride, height); src = cairo_image_surface_create_for_data (data, format, width, height, stride); cr_src = cairo_create (src); cairo_set_source_surface (cr_src, png, 0, 0); cairo_paint (cr_src); cairo_destroy (cr_src); cairo_set_source_surface (cr, src, 0, 0); cairo_paint (cr); cairo_surface_destroy (png); cairo_surface_finish (src); cairo_surface_destroy (src); free (data); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *image; cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); image = cairo_test_create_surface_from_png (ctx, png_filename); cairo_set_source_surface (cr, image, 0, 0); /* simple clip */ cairo_save (cr); cairo_rectangle (cr, 2, 2, 16, 16); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* unaligned clip */ cairo_save (cr); cairo_rectangle (cr, 2.5, 2.5, 15, 15); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); cairo_translate (cr, -WIDTH, HEIGHT); /* aligned-clip */ cairo_save (cr); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_rectangle (cr, 0, 0, 20, 20); cairo_rectangle (cr, 3, 3, 10, 10); cairo_rectangle (cr, 7, 7, 10, 10); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* force a clip-mask */ cairo_save (cr); cairo_arc (cr, 10, 10, 10, 0, 2 * M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, 10, 10, 5, 2 * M_PI, 0); cairo_new_sub_path (cr); cairo_arc (cr, 10, 10, 2, 0, 2 * M_PI); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); return CAIRO_TEST_SUCCESS; }
static void draw_image (const cairo_test_context_t *ctx, cairo_t *cr) { cairo_surface_t *surface, *similar; surface = cairo_test_create_surface_from_png (ctx, png_filename); similar = clone_similar_surface (cairo_get_group_target (cr), surface); cairo_surface_destroy (surface); cairo_set_source_surface (cr, similar, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); cairo_surface_destroy (similar); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *surface; surface = cairo_test_create_surface_from_png (ctx, png_filename); cairo_set_source_surface (cr, surface, 32, 32); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REFLECT); cairo_paint (cr); cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
cairo_pattern_t * cairo_test_create_pattern_from_png (const char *filename) { cairo_surface_t *image; cairo_pattern_t *pattern; image = cairo_test_create_surface_from_png (filename); pattern = cairo_pattern_create_for_surface (image); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_surface_destroy (image); return pattern; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *surface; cairo_surface_t *similar; surface = cairo_test_create_surface_from_png (png_filename); similar = clone_similar_surface (cairo_get_group_target (cr), surface); cairo_set_source_surface (cr, similar, 32, 32); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REFLECT); cairo_paint (cr); cairo_surface_destroy (similar); cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *image, *mask; image = cairo_test_create_surface_from_png (ctx, png_filename); mask = create_mask (cr, 40, 40); /* opaque background */ cairo_paint (cr); /* center */ cairo_translate (cr, (width - cairo_image_surface_get_width (image)) / 2., (height - cairo_image_surface_get_height (image)) / 2.); /* rotate 30 degree around the center */ cairo_translate (cr, width/2., height/2.); cairo_rotate (cr, -30 * 2 * M_PI / 360); cairo_translate (cr, -width/2., -height/2.); /* place the image on our surface */ cairo_set_source_surface (cr, image, 0, 0); /* reset the drawing matrix */ cairo_identity_matrix (cr); /* fill nicely */ cairo_scale (cr, width / 40., height / 40.); /* apply the mask */ cairo_mask_surface (cr, mask, 0, 0); cairo_surface_destroy (mask); cairo_surface_destroy (image); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *image; image = cairo_test_create_surface_from_png (ctx, png_filename); cairo_set_source_rgba (cr, 0, 0, 0, 1); cairo_rectangle (cr, 0, 0, SIZE, SIZE); cairo_fill (cr); cairo_translate (cr, OFFSET, OFFSET); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_surface (cr, image, 0, 0); cairo_rectangle (cr, 0, 0, SIZE - OFFSET, SIZE - OFFSET); cairo_fill (cr); cairo_surface_destroy (image); return CAIRO_TEST_SUCCESS; }
/* Draw an image scaled down, with antialiasing disabled */ static cairo_test_status_t draw (cairo_t *cr, int width, int height, cairo_filter_t filter) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *image; double x_scale, y_scale, scale; cairo_set_source_rgb (cr, 1, 1, 1); image = cairo_test_create_surface_from_png (ctx, png_filename); x_scale = width * 1.0 / cairo_image_surface_get_width (image); y_scale = height * 1.0 / cairo_image_surface_get_height (image); scale = x_scale < y_scale ? x_scale : y_scale; cairo_save (cr); cairo_scale (cr, scale, scale); cairo_set_source_surface (cr, image, 0, 0); cairo_pattern_set_filter (cairo_get_source (cr), filter); cairo_paint (cr); cairo_restore (cr); cairo_surface_destroy (image); return CAIRO_TEST_SUCCESS; }