[cairo] missing transform inside SVG output - difference to PNG output

Patrick Fritzsch Patrick.Fritzsch at cib.de
Fri Jun 19 07:38:18 PDT 2015


Hello,

With current cairo version (and old 1.12.8 version) i have a problem, which I currently don't understand.
I did put a sample code into cmsample.cpp - or also see below.

When you run it, you get 2 output files. Both, the png file and svg file *should* have the same content, but they don't.
The SVG file is wrong.

When I comment inside the code the following line
cairo_set_source_rgb (ctx, 1, 1, 1);

the svg file becomes correct. The difference is, that suddenly
<use xlink:href="#image5"/>
becomes
<use xlink:href="#image5" transform="matrix(0.5,0,0,-0.5,250,350)"/>
inside the SVG file.

Inside the sample code, there are 2 calls to cairo_set_source_rgb. One before and one after
cairo_matrix_init(&matrix, 0.5, 0.00, 0.00, -0.5, 250, 350);

When I omit the first cairo_set_source_rgb call, then inside the second call inside
_cairo_default_context_set_source_rgba

"if (_current_source_matches_solid (cr->gstate->source,
                                             red, green, blue, alpha))
         return CAIRO_STATUS_SUCCESS;"

becomes true.

When I don't omit it, then it is false and inside the
_cairo_gstate_set_source
gstate->source_ctm_inverse = gstate->ctm_inverse;

source_ctm_inverse is set - which is an inverse to the matrix I did set - That's the difference I debugged before the output to SVG happens.

Later in _cairo_svg_surface_emit_transform
The "if (!_cairo_matrix_is_identity (&matrix))" matrix becomes the identity matrix and the transform section is not written.

I do not know much about cairo internals, so currently i dont know, what a correct fix would be. Can someone please help?

Cheers,
Patrick

<---------------------------
Sample code:

void debug_cairo_mask()
{

         cairo_surface_t* surf = cairo_svg_surface_create ("test_out.svg", 595, 842);
         cairo_t* ctx = cairo_create(surf);

         cairo_matrix_t matrix;

         cairo_set_source_rgb (ctx, 1, 1, 1);
         cairo_fill(ctx);

         cairo_surface_t* mask_surf = cairo_image_surface_create_from_png("mask.png");
         if (cairo_surface_status(mask_surf) == CAIRO_STATUS_SUCCESS)
         {
                   cairo_pattern_t* mask_pattern = cairo_pattern_create_for_surface(mask_surf);

                   cairo_save(ctx);
                   cairo_matrix_init(&matrix, 0.5, 0.00, 0.00, -0.5, 250, 350);
                   /*cairo_matrix_init(&matrix, 0.5, 0.00, 0.00, 0.5, 250, 350);*/
                   cairo_set_matrix(ctx, &matrix);

                   cairo_set_source_rgb(ctx,0,0,0);
                   cairo_mask(ctx, mask_pattern);

                   cairo_pattern_destroy(mask_pattern);
                   cairo_surface_destroy(mask_surf);

                   cairo_restore(ctx);
                   cairo_surface_write_to_png(surf, "test_out.png");
         }
         else
         {
                   printf("Can not create surface from file \"mask.png\". Check that the file exists and is not corrupted.\n\n");
         }
         cairo_destroy(ctx);
         cairo_surface_destroy(surf);
}
-------------------------->

Patrick Fritzsch
Diplom Informatiker
CIB PDF Support
---
CIB software GmbH
Elektrastr. 6a
81925 München
---
T +49 (0)89 / 1 43 60 -111
F +49 (0)89 / 1 43 60 -100
www.cib.de
---
Sitz: München
Registergericht München, HRB 123286
Geschäftsführer: Dipl.-Ing. Ulrich Brandner

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150619/d35fca94/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cmsample.cpp
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150619/d35fca94/attachment-0001.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mask.png
Type: image/png
Size: 8059 bytes
Desc: mask.png
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150619/d35fca94/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_out.svg
Type: image/svg+xml
Size: 11474 bytes
Desc: test_out.svg
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150619/d35fca94/attachment-0001.svg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_out.png
Type: image/png
Size: 5763 bytes
Desc: test_out.png
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150619/d35fca94/attachment-0003.png>


More information about the cairo mailing list