[cairo] Recording surface cannot be painted to another recording surface
mario.huettel at gmx.net
Mon Jul 23 07:45:49 UTC 2018
I'm trying to copy a recording surface to another recording surface.
However, this does not work as expected. The documentation says:
The recording surface can then be "replayed" against any target surface
by using it as a source surface.
It says ANY target surface but it doesn't work.
I've included a minimal working example. It draws a line into a recording
surface, prints its size and copies the surface to another recording
prints the size of the second surface.
The expected output is, that both sizes are the smae and that the second
contains the same stuff as the first one.
I changed the second recording surface to a PDF-surface. In this case
the copying works and the PDF contains the correct image.
I hope someone can help me.
cairo_surface_t *surface, *surface2;
cairo_t *cr, *cr2;
double x0, y0, w, h;
/* First recording surface with some line */
surface = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0, 1, 0);
cairo_move_to(cr, 1, 1);
cairo_rel_line_to(cr, 100.0, 30.0);
cairo_recording_surface_ink_extents(surface, &x0, &y0, &w, &h);
printf("Size of surface: %lf %lf at %lf %lf\n", w, h, x0, y0);
/* Second recording surface. Copy first one */
surface2 = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA,
cr2 = cairo_create(surface2);
cairo_set_source_surface(cr2, surface, 0.0, 0.0);
cairo_recording_surface_ink_extents(surface2, &x0, &y0, &w, &h);
printf("Size of surface2: %lf %lf at %lf %lf\n", w, h, x0, y0);
/* Clean up */
More information about the cairo