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

Ḿario Hüttel mario.huettel at gmx.net
Mon Jul 30 10:30:58 UTC 2018


Today I realized that I can copy a recording surface to a PDF surface
without any problems. Converting the same recording surface to an SVG
surface results in an SVG file that cannot be displayed by any program.

The drawing inside the recording surface is about 100x100 pixels big.
Transfering it to an SVG surface results in complete garbage in the SVG
file. On the recording surface I draw some boxes with coordinates
between 0 and 100. This is an example line that is put into the SVG
file. I'm no expert with SVG but these numbers seem pretty random and
big. What's going on here?

<path style="fill:none;stroke-width:0.0001;stroke-linecap:butt;stroke-
linejoin:miter;stroke:rgb(12.54902%,29.019608%,52.941176%);stroke-
opacity:1;stroke-miterlimit:10;" d="M
20893050494894192919008793909236355953531607760860494047118354313036740
47950378618951477302065627841831178842717056837631637135412762763476942
88425131021829949979526313257399133358625140067080109529559163503838194
48167889137752767560554632302910945261832229617664 110 L
20893050494894192919008793909236355953531607760860494047118354313036740
47950378618951477302065627841831178842717056837631637135412762763476942
88425131021829949979526313257399133358625140067080109529559163503838194
48167889137752767560554632302910945261832229617664 110 L
20893050494894192919008793909236355953531607760860494047118354313036740
47950378618951477302065627841831178842717056837631637135412762763476942
88425131021829949979526313257399133358625140067080109529559163503838194
48167889137752767560554632302910945261832229617664 120 L
20893050494894192919008793909236355953531607760860494047118354313036740
47950378618951477302065627841831178842717056837631637135412762763476942
88425131021829949979526313257399133358625140067080109529559163503838194
48167889137752767560554632302910945261832229617664 120 Z M
20893050494894192919008793909236355953531607760860494047118354313036740
47950378618951477302065627841831178842717056837631637135412762763476942
88425131021829949979526313257399133358625140067080109529559163503838194
48167889137752767560554632302910945261832229617664 110 "
transform="matrix(1,0,0,-1,-
20893050494894192919008793909236355953531607760860494047118354313036740
47950378618951477302065627841831178842717056837631637135412762763476942
88425131021829949979526313257399133358625140067080109529559163503838194
48167889137752767560554632302910945261832229617664,-0)"/>

Is the recording surface some experimental feature? I'm experiencing a
lot of trouble with it.

Mario

On Mon, 2018-07-23 at 09:45 +0200, Mario Hüttel wrote:
> 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