static cairo_surface_t * _cairo_boilerplate_quartz_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, void **closure) { cairo_format_t format; format = cairo_boilerplate_format_from_content (content); *closure = NULL; return cairo_quartz_surface_create (format, width, height); }
static cairo_surface_t * _cairo_boilerplate_test_paginated_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { test_paginated_closure_t *tpc; cairo_format_t format; cairo_surface_t *surface; cairo_status_t status; *closure = tpc = xmalloc (sizeof (test_paginated_closure_t)); format = cairo_boilerplate_format_from_content (content); tpc->target = cairo_image_surface_create (format, ceil (width), ceil (height)); surface = _cairo_test_paginated_surface_create (tpc->target); if (cairo_surface_status (surface)) goto CLEANUP; status = cairo_surface_set_user_data (surface, &test_paginated_closure_key, tpc, NULL); if (status == CAIRO_STATUS_SUCCESS) return surface; cairo_surface_destroy (surface); surface = cairo_boilerplate_surface_create_in_error (status); cairo_surface_destroy (tpc->target); CLEANUP: free (tpc); return surface; }
/* The only reason we go through all these machinations to write a PNG * image is to _really ensure_ that the data actually landed in our * buffer through the paginated surface to the test_paginated_surface. * * If we didn't implement this function then the default * cairo_surface_write_to_png would result in the paginated_surface's * acquire_source_image function replaying the meta-surface to an * intermediate image surface. And in that case the * test_paginated_surface would not be involved and wouldn't be * tested. */ cairo_status_t _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface, const char *filename) { cairo_surface_t *image; cairo_format_t format; test_paginated_closure_t *tpc; cairo_status_t status; /* show page first. the automatic show_page is too late for us */ /* XXX use cairo_surface_show_page() when that's added */ cairo_t *cr = cairo_create (surface); cairo_show_page (cr); cairo_destroy (cr); tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key); format = cairo_boilerplate_format_from_content (tpc->content); image = cairo_image_surface_create_for_data (tpc->data, format, tpc->width, tpc->height, tpc->stride); status = cairo_surface_write_to_png (image, filename); if (status) { CAIRO_BOILERPLATE_LOG ("Error writing %s: %s. Exiting\n", filename, cairo_status_to_string (status)); exit (1); } cairo_surface_destroy (image); return CAIRO_STATUS_SUCCESS; }
static cairo_surface_t * _cairo_boilerplate_test_wrapping_create_surface (const char *name, cairo_content_t content, double width, double height, double max_width, double max_height, cairo_boilerplate_mode_t mode, int id, void **closure) { cairo_surface_t *target; cairo_surface_t *surface; cairo_format_t format; *closure = NULL; format = cairo_boilerplate_format_from_content (content); target = cairo_image_surface_create (format, ceil (width), ceil (height)); surface = _cairo_test_wrapping_surface_create (target); cairo_surface_destroy (target); return surface; }