Skip Menu |

This queue is for tickets about the SVG-Rasterize CPAN distribution.

Report information
The Basics
Id: 58114
Status: resolved
Priority: 0/
Queue: SVG-Rasterize

People
Owner: LGEHLEN [...] cpan.org
Requestors: RENEEB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.003000
Fixed in: 0.003002



Subject: Problems with simple SVGs
Hi Lutz, I've a very simple SVG: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <text x="20" y="100" style="stroke: #000000;">Perl ist genial</text> </svg> And I want to "rasterize" this SVG with this program: #!/usr/bin/perl use strict; use warnings; use SVG::Parser; use SVG::Rasterize; my $parser = SVG::Parser->new->parsefile( 'test.svg' ); my $raster = SVG::Rasterize->new; $raster->rasterize( svg => $parser, width => 600, height => 300, engine_class => 'SVG::Rasterize::Cairo', ); $raster->write( type => 'png', file_name => 'test.png' ); All I get is this error: Use of uninitialized value $value in sprintf at /usr/local/share/perl/5.10.0/SVG/Rasterize/Exception.pm line 109. Failed to process the HASH(0xa01b6f0) string '' correctly. Please report this as a bug and include the string into the bug report. - Renée
Hi Renée, thank you for your bug report. I could reproduce the problem. On Fri Jun 04 04:33:31 2010, RENEEB wrote: Show quoted text
> I've a very simple SVG: > > <svg xmlns="http://www.w3.org/2000/svg" > xmlns:xlink="http://www.w3.org/1999/xlink"> > <text x="20" y="100" style="stroke: #000000;">Perl ist
genial</text> Show quoted text
> </svg>
The bug has two aspects: 1) I have not tried SVG::Parser intensively. Therefore I was not aware that it already parses the value of the style attribute into a hash. The code of SVG::Rasterize therefore treats the hash reference as a scalar and when it tries to trim leading and trailing white space the hash reference is turned into a string. Additionally to losing the hash, a subsequent parameter validation then does not detect the hashref any more. 2) After detection of an invalid style string 'HASH...', the exception method is accidentally called as a subroutine instead of as a method which leads to the weird error message. I have fixed both bugs and will release a new version soon. As a workaround, you could use the stroke attribute instead of the style attribute like this: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <text x="20" y="100" stroke="rgb(0, 0, 0)">Perl ist genial</text> </svg> However, there are two more problems: 1) Currently, SVG::Rasterize only understands rgb color settings, no hex values. This is not documented, I'm sorry. I will fix that. In the example above, I have already replaced '#000000' by 'rgb(0, 0, 0)'. 2) SVG::Rasterize does not rasterize text, yet. Therefore, your example will produce an empty image. At least, this is documented for a change, uff ;-). I am currently working on it, it's the main goal for version 0.004. Currently, only paths and basic shapes are supported. Thanks for trying SVG::Rasterize and for reporting the bug Lutz P.S.: You have indicated that the bug occurred in version 0.003000. This version has another problem which is already fixed in 0.003001. Please upgrade.
Subject: Re: [rt.cpan.org #58114] Problems with simple SVGs
Date: Fri, 04 Jun 2010 13:59:46 +0200
To: bug-SVG-Rasterize [...] rt.cpan.org
From: Renee Bäcker <perl [...] renee-baecker.de>
Hi Lutz, thanks for your quick response. Show quoted text
> Thanks for trying SVG::Rasterize and for reporting the bug > Lutz >
Thanks for SVG::Rasterize. Please keep on working on this module ;-) Show quoted text
> P.S.: You have indicated that the bug occurred in version 0.003000. > This version has another problem which is already fixed in 0.003001. > Please upgrade. >
- Renée
Hello Renée, sorry, even simple text support took a while. The reason is that under certain circumstances text elements can only be rasterized once all their children have been processed. Therefore, rasterization has to be deferred and the information to rasterize the whole text element has to be kept in a buffer. It took me until now to implement the respective framework. However, I have released version 0.003002 which has basic text support and also fixes the bug you encountered. A few notes on your example: 1) Support for hex colors is still not supported. There is always more stuff to do and I wanted to release a fix for this bug now. You can set the color either as 'black' or as 'rgb(0, 0, 0)'. 2) You should not set the stroke color. Usually in vector graphics, the color of text is set as the fill color (which is black by default in SVG). The stroke is only used two explicitly draw the outline of text. In your case, the text will look rather ugly with the stroke because the letters are thicker than intended by the font designer. 3) In the example, the text is quite small. Currently, the text support of SVG::Rasterize is really only a proof of concept, and the font-size property is not supported, yet. To see a bit more, you could work around that using the transform attribute. If you like you could try this example. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <text x="5" y="25" transform="scale(4)">Perl ist genial</text> </svg> Thanks again for your bug report, Lutz