[cairo] Recording surface cannot be painted to another recording surface

Mario Hüttel mario.huettel at gmx.net
Mon Jul 23 07:45:49 UTC 2018


Hello,

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
surface and
prints the size of the second surface.

The expected output is, that both sizes are the smae and that the second
surface
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.

Example code:

-----

#include <cairo.h>
#include <stdio.h>

int main(void)
{
  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_set_line_width(cr, 10);
  cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
  cairo_move_to(cr, 1, 1);
  cairo_rel_line_to(cr, 100.0, 30.0);
  cairo_stroke(cr);

  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,
NULL);
  cr2 = cairo_create(surface2);   
 
  cairo_set_source_surface(cr2, surface, 0.0, 0.0);
  cairo_paint(cr2);

  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 */
  cairo_destroy(cr);
  cairo_surface_destroy(surface);
  cairo_destroy(cr2);
  cairo_surface_destroy(surface2);

  return 0;
}




More information about the cairo mailing list