From b5175fd8a6c8ff555e0a127e3fe42cdad241aad1 Mon Sep 17 00:00:00 2001 From: Anton Danilkin Date: Wed, 11 Nov 2020 17:33:31 +0100 Subject: Fix testing in the full mode for PDF, PS and SVG backends Fix how offset, scale and transparency are handled. Also do the same change in the "win32-printing" backend as it has a copy of the code from PDS, PS and SVG backends. --- boilerplate/cairo-boilerplate-pdf.c | 33 ++++++++++------- boilerplate/cairo-boilerplate-ps.c | 50 ++++++++++++++++++-------- boilerplate/cairo-boilerplate-svg.c | 44 ++++++++++++++++------- boilerplate/cairo-boilerplate-win32-printing.c | 24 ++++++++----- 4 files changed, 103 insertions(+), 48 deletions(-) (limited to 'boilerplate') diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c index c6c6b634c..4669040b9 100644 --- a/boilerplate/cairo-boilerplate-pdf.c +++ b/boilerplate/cairo-boilerplate-pdf.c @@ -120,16 +120,20 @@ _cairo_boilerplate_pdf_finish_surface (cairo_surface_t *surface) &pdf_closure_key); cairo_status_t status; - /* Both surface and ptc->target were originally created at the - * same dimensions. We want a 1:1 copy here, so we first clear any - * device offset on surface. - * - * In a more realistic use case of device offsets, the target of - * this copying would be of a different size than the source, and - * the offset would be desirable during the copy operation. */ - cairo_surface_set_device_offset (surface, 0, 0); - if (ptc->target) { + /* Both surface and ptc->target were originally created at the + * same dimensions. We want a 1:1 copy here, so we first clear any + * device offset and scale on surface. + * + * In a more realistic use case of device offsets, the target of + * this copying would be of a different size than the source, and + * the offset would be desirable during the copy operation. */ + double x_offset, y_offset; + double x_scale, y_scale; + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (surface, 0, 0); + cairo_surface_set_device_scale (surface, 1, 1); cairo_t *cr; cr = cairo_create (ptc->target); cairo_set_source_surface (cr, surface, 0, 0); @@ -137,6 +141,8 @@ _cairo_boilerplate_pdf_finish_surface (cairo_surface_t *surface) cairo_show_page (cr); status = cairo_status (cr); cairo_destroy (cr); + cairo_surface_set_device_offset (surface, x_offset, y_offset); + cairo_surface_set_device_scale (surface, x_scale, y_scale); if (status) return status; @@ -196,11 +202,14 @@ _cairo_boilerplate_pdf_get_image_surface (cairo_surface_t *surface, int height) { cairo_surface_t *image; + double x_offset, y_offset; + double x_scale, y_scale; image = _cairo_boilerplate_pdf_convert_to_image (surface, page); - cairo_surface_set_device_offset (image, - cairo_image_surface_get_width (image) - width, - cairo_image_surface_get_height (image) - height); + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (image, x_offset, y_offset); + cairo_surface_set_device_scale (image, x_scale, y_scale); surface = _cairo_boilerplate_get_image_surface (image, 0, width, height); cairo_surface_destroy (image); diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c index ae61239f3..2c4c94f0e 100644 --- a/boilerplate/cairo-boilerplate-ps.c +++ b/boilerplate/cairo-boilerplate-ps.c @@ -178,24 +178,29 @@ _cairo_boilerplate_ps_finish_surface (cairo_surface_t *surface) &ps_closure_key); cairo_status_t status; - /* Both surface and ptc->target were originally created at the - * same dimensions. We want a 1:1 copy here, so we first clear any - * device offset on surface. - * - * In a more realistic use case of device offsets, the target of - * this copying would be of a different size than the source, and - * the offset would be desirable during the copy operation. */ - cairo_surface_set_device_offset (surface, 0, 0); - if (ptc->target) { + /* Both surface and ptc->target were originally created at the + * same dimensions. We want a 1:1 copy here, so we first clear any + * device offset and scale on surface. + * + * In a more realistic use case of device offsets, the target of + * this copying would be of a different size than the source, and + * the offset would be desirable during the copy operation. */ + double x_offset, y_offset; + double x_scale, y_scale; + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (surface, 0, 0); + cairo_surface_set_device_scale (surface, 1, 1); cairo_t *cr; - cr = cairo_create (ptc->target); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_show_page (cr); status = cairo_status (cr); cairo_destroy (cr); + cairo_surface_set_device_offset (surface, x_offset, y_offset); + cairo_surface_set_device_scale (surface, x_scale, y_scale); if (status) return status; @@ -244,6 +249,8 @@ _cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface, { ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key); + double x_offset, y_offset; + double x_scale, y_scale; char *filename; cairo_status_t status; @@ -259,15 +266,28 @@ _cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface, free (filename); xasprintf (&filename, "%s-%05d.png", ptc->filename, page); } - surface = cairo_boilerplate_get_image_surface_from_png (filename, - width, - height, - ptc->target == NULL); + cairo_surface_t *converted = cairo_boilerplate_get_image_surface_from_png (filename, + ptc->width, + ptc->height, + ptc->target == NULL); remove (filename); free (filename); - return surface; + cairo_surface_t *image = cairo_image_surface_create(ptc->target ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32, + width, + height); + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (converted, x_offset, y_offset); + cairo_surface_set_device_scale (converted, x_scale, y_scale); + cairo_t *cr = cairo_create (image); + cairo_set_source_surface (cr, converted, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); + cairo_surface_destroy (converted); + + return image; } static void diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c index 797106ea6..bbef30aed 100644 --- a/boilerplate/cairo-boilerplate-svg.c +++ b/boilerplate/cairo-boilerplate-svg.c @@ -152,16 +152,20 @@ _cairo_boilerplate_svg_finish_surface (cairo_surface_t *surface) &svg_closure_key); cairo_status_t status; - /* Both surface and ptc->target were originally created at the - * same dimensions. We want a 1:1 copy here, so we first clear any - * device offset on surface. - * - * In a more realistic use case of device offsets, the target of - * this copying would be of a different size than the source, and - * the offset would be desirable during the copy operation. */ - cairo_surface_set_device_offset (surface, 0, 0); - if (ptc->target) { + /* Both surface and ptc->target were originally created at the + * same dimensions. We want a 1:1 copy here, so we first clear any + * device offset and scale on surface. + * + * In a more realistic use case of device offsets, the target of + * this copying would be of a different size than the source, and + * the offset would be desirable during the copy operation. */ + double x_offset, y_offset; + double x_scale, y_scale; + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (surface, 0, 0); + cairo_surface_set_device_scale (surface, 1, 1); cairo_t *cr; cr = cairo_create (ptc->target); cairo_set_source_surface (cr, surface, 0, 0); @@ -169,6 +173,8 @@ _cairo_boilerplate_svg_finish_surface (cairo_surface_t *surface) cairo_show_page (cr); status = cairo_status (cr); cairo_destroy (cr); + cairo_surface_set_device_offset (surface, x_offset, y_offset); + cairo_surface_set_device_scale (surface, x_scale, y_scale); if (status) return status; @@ -228,15 +234,29 @@ _cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface, int height) { cairo_surface_t *image; + double x_offset, y_offset; + double x_scale, y_scale; + svg_target_closure_t *ptc = cairo_surface_get_user_data (surface, + &svg_closure_key); if (page != 0) return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); image = _cairo_boilerplate_svg_convert_to_image (surface); - cairo_surface_set_device_offset (image, - cairo_image_surface_get_width (image) - width, - cairo_image_surface_get_height (image) - height); + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (image, x_offset, y_offset); + cairo_surface_set_device_scale (image, x_scale, y_scale); surface = _cairo_boilerplate_get_image_surface (image, 0, width, height); + if (ptc->target) { + cairo_surface_t *old_surface = surface; + surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); + cairo_t *cr = cairo_create (surface); + cairo_set_source_surface (cr, old_surface, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); + cairo_surface_destroy (old_surface); + } cairo_surface_destroy (image); return surface; diff --git a/boilerplate/cairo-boilerplate-win32-printing.c b/boilerplate/cairo-boilerplate-win32-printing.c index 5a630664b..4bc1dd459 100644 --- a/boilerplate/cairo-boilerplate-win32-printing.c +++ b/boilerplate/cairo-boilerplate-win32-printing.c @@ -270,22 +270,28 @@ _cairo_boilerplate_win32_printing_surface_write_to_png (cairo_surface_t *surface cairo_t *cr; cairo_status_t status; - /* Both surface and ptc->target were originally created at the - * same dimensions. We want a 1:1 copy here, so we first clear any - * device offset on surface. - * - * In a more realistic use case of device offsets, the target of - * this copying would be of a different size than the source, and - * the offset would be desirable during the copy operation. */ - cairo_surface_set_device_offset (surface, 0, 0); - if (ptc->target) { + /* Both surface and ptc->target were originally created at the + * same dimensions. We want a 1:1 copy here, so we first clear any + * device offset and scale on surface. + * + * In a more realistic use case of device offsets, the target of + * this copying would be of a different size than the source, and + * the offset would be desirable during the copy operation. */ + double x_offset, y_offset; + double x_scale, y_scale; + cairo_surface_get_device_offset (surface, &x_offset, &y_offset); + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); + cairo_surface_set_device_offset (surface, 0, 0); + cairo_surface_set_device_scale (surface, 1, 1); cairo_t *cr; cr = cairo_create (ptc->target); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_show_page (cr); cairo_destroy (cr); + cairo_surface_set_device_offset (surface, x_offset, y_offset); + cairo_surface_set_device_scale (surface, x_scale, y_scale); cairo_surface_finish (surface); surface = ptc->target; -- cgit v1.2.1