missing transform inside SVG output - difference to PNG output

Patrick Fritzsch <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
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

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
cmsample.cpp (text/plain, 1.1 KB)
#include "cairo.h"
#include "cairo-svg.h"
#include <stdio.h>


// Debug code for cairo_mask
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);
}
mask.png (image/png, 7.9 KB) - not displayed
test_out.svg (image/svg+xml, 11.2 KB) - not displayed
test_out.png (image/png, 5.6 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.