[cairo] svg_cairo_get_size problem

mental at rydia.net mental at rydia.net
Fri Jun 24 10:49:58 PDT 2005


Quoting Carl Worth <cworth at cworth.org>:

> 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"

Since SVG paths cannot be specified in anything but px, in practice
the "same units as the rest of the drawing" must always be px.

> Meanwhile, in cornwall.svg (which fails), the overall size is
> specified with real-world units (in this case, millimeters):
>
> 	width="234mm"
> 	height="140mm"
>

> 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.

If you need constant-sized documents without changing contents, you
can specify the dimensions in real-world units and use viewBox to
force a specific "effective DPI".

e.g. for a 3in x 2in document at 100dpi:

 <svg width="3in" height="2in" viewBox="0 0 300 200">...

Note that viewBox doesn't really change the DPI, it just applies a
scaling transformation.  So while px will now render at consistent
physical size, other absolute units will no longer do so.

-mental



More information about the cairo mailing list