[cairo] Recording surfaces fail to replay onto SVG surfaces

Adrian Johnson ajohnson at redneon.com
Thu Oct 12 11:13:37 UTC 2017


On 12/10/17 21:01, Antonio Ospite wrote:
> On Thu, 5 Oct 2017 20:54:53 +1030
> ajohnson at redneon.com (Adrian Johnson) wrote:
> 
>> I've pushed a fix for painting unbounded recordings to the SVG surface.
>>
> 
> Hi
> 
> I too experienced a similar problem recently.
> 
> The changes in 5a9dba9929d9 seem to fix the original test case of
> replaying to an SVG surface, but only for the first time: I noticed that
> replaying a second time still fails, producing an empty SVG.

I'll have a look this weekend.

> BTW, these seems to be regressions as 1.14.10 works fine in both cases.
> 
> I also noticed that the generated files look a little different when
> using the current master: groups and links are used for the replayed
> surfaces, while with 1.14.10 the replayed elements are drawn ungrouped,
> I don't know if the regression is related to this change.
> 
> I can bisect if necessary.

I did that with the previous fix. It doesn't help as the problem is not
due to a change in the svg backend. It is just the svg code hasn't been
kept up to date with changes to the core code.

> 
> See the following test program, it works as (I think) it should with
> 1.14.10, but not with the current master (d5b634da6159):
> 
> ----------------------------------------------------------------------
> #include <stdio.h>
> #include <cairo/cairo.h>
> #include <cairo/cairo-svg.h>
> 
> #ifndef M_PI
> #define M_PI 3.14159265358979323846
> #endif
> 
> static void save_as_svg(cairo_surface_t *surface, double width, double height, const char *filename)
> {
> 	cairo_surface_t *output;
> 	cairo_t *ctx;
> 
> 	output = cairo_svg_surface_create(filename, width, height);
> 
> 	ctx = cairo_create(output);
> 
> 	cairo_set_source_surface(ctx, surface, 0.0, 0.0);
> 	cairo_paint(ctx);
> 
> 	cairo_destroy(ctx);
> 	cairo_surface_destroy(output);
> }
> 
> static void save_as_png(cairo_surface_t *surface, double width, double height, const char *filename)
> {
> 	cairo_surface_t *output;
> 	cairo_t *ctx;
> 
> 	output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
> 	ctx = cairo_create(output);
> 
> 	cairo_set_source_surface(ctx, surface, 0.0, 0.0);
> 	cairo_paint(ctx);
> 	cairo_surface_write_to_png(output, filename);
> 
> 	cairo_destroy(ctx);
> 	cairo_surface_destroy(output);
> }
> 
> int main(void)
> {
> 	cairo_surface_t *surface;
> 	cairo_t *ctx;
> 	double x;
> 	double y;
> 	double width;
> 	double height;
> 
> 	surface = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
> 
> 	ctx = cairo_create(surface);
> 
> 	cairo_rectangle(ctx, 0.0, 0.0, 300, 300);
> 	cairo_set_source_rgb(ctx, 0.3, 0.6, 0.8);
> 	cairo_fill(ctx);
> 
> 	cairo_arc(ctx, 150, 150, 100, 0, 2 * M_PI);
> 	cairo_set_source_rgb(ctx, 1, 1, 1);
> 	cairo_stroke(ctx);
> 
> 	cairo_destroy(ctx);
> 
> 	cairo_recording_surface_ink_extents(surface, &x, &y, &width, &height);
> 	printf("recording surface ink extents: %f, %f, %f, %f\n", x, y, width, height);
> 
> 	/* SVG output */
> 	save_as_svg(surface, width, height, "svg_first_time.svg");
> 	save_as_svg(surface, width, height, "svg_second_time.svg");
> 
> 	/* PNG output for comparison */
> 	save_as_png(surface, width, height, "png_reference_output.png");
> 
> 	cairo_surface_destroy(surface);
> 	return 0;
> }
> ----------------------------------------------------------------------
> 
> Ciao,
>    Antonio
> 



More information about the cairo mailing list