[cairo] svg_cairo_get_size problem
Carl Worth
cworth at cworth.org
Fri Jun 24 10:11:40 PDT 2005
On Fri, 24 Jun 2005 01:55:49 -0400, Jason Dorje Short wrote:
> The attached SVGs (chosen for their smallness) show a working and a
> nonworking SVG file. If you use svg2png or xsvg on the cornwall flag it
> will be incorrect, but on the galicia flag it works correctly (or at
> least I think so; if not I have other examples that do work
> correctly).
The first thing worth noting is that in galicia.svg (which works) the
overall size is provided in unit-less values:
width="999.000000"
height="666.000000"
which, according to the SVG specification means that these values
determine the size in "pixels" (i.e., a px unit as defined by CSS2).
Meanwhile, in cornwall.svg (which fails), the overall size is
specified with real-world units (in this case, millimeters):
width="234mm"
height="140mm"
So, converting those real-world units to pixels requires information
about the real-world dimension of a pixel. In libsvg there's
definitely a bug that there's no way to set that value, (instead it
always assumes 100 pixels per inch).
But that's not what's causing the strange behavior you're seeing.
In cornwall.svg, after specifying the size as 234x140mm the first
thing drawn is the "background" rectangle which has a size specified
as:
width="829.133850"
height="496.062988"
These values don't have real-world units, so according to the SVG
specification[*] they should be interpreted as pixels. And ~ 829x496
pixels is only equivalent to 234x140mm if the pixels are sized such
that there are 90 pixels per inch, (which must be the assumed
pixels-per-inch value of the tool used to create this file).
Therefore, the overall size of the SVG file changes depending on the
pixels-per-inch value, but the actual drawing contents do not. And
this is exactly the behavior you're seeing with libsvg-cairo.
My recommendation for you is to just alter the top-level width and
height attributes to use the same units as the rest of the
drawing. That is, use:
width="829"
height="496"
This eliminates the 90 pixels per inch assumption from the file, and
also happens to avoid the need for a set_dpi function in
libsvg.
It would still be nice to have something like svg_set_dpi but it
wouldn't be an adequate solution for this file. It would allow correct
rendering at 90 DPI but not at any other value.
Does that make sense? Is there anything else I'm missing here?
-Carl
[*] http://www.w3.org/TR/2003/REC-SVG11-20030114/coords.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050624/cc164cff/attachment.pgp
More information about the cairo
mailing list