Comment 8 for bug 1394725

Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :

Yes, an 'in' is always '96px', except when it isn't...

In any particular context, an 'in' is equal to 96 'user unit' which in SVG is the same as a 'px'. This number has been fixed by the CSS Gods.

However, the overall scale of a drawing is determined by the ratio of the SVG root 'width'/'height' attributes to the 'viewBox'. This sets the 'real world' value of the 'user unit'. When you change the default unit identifier from 'px' to 'mm' in the current version of 0.91 the 'viewBox' is changed so that one 'user unit' in the real world is equal to one millimeter. Inkscape then proceeds to change all the internal values to match. This is like applying a scaling transform to the whole drawing. So:

A length of 90px (or 67.5pt) then becomes a length of 23.8125px since one 'user unit' (px) is now equal to 1mm in the 'real world'. 23.8125px could also be written as 0.24805in since 1in = 96px, but again this length needs to be scaled by the overall drawing scale as determined by the SVG root 'width'/'height' and 'viewBox' attributes.

There are two practical approaches for dealing with units in SVG:

1. Set the overall scale using the SVG root 'width'/'height' and 'viewBox' attributes and don't use absolute units inside the SVG file. Example: <svg width='20mm' height="20mm' viewBox="0 0 20 20" ...>. Here one 'user unit' is fixed to have a real world value of 1mm.

2. Fix the overall scale to '1' by using the same values for the SVG root 'width'/'height' and 'viewBox' attributes. Example: <svg width="200" height="200" viewBox="0 0 200 200". Here lengths using absolute unit identifiers will have their expected meanings inside the file. (Except Inkscape 0.91 and earlier uses incorrectly 90px per inch.)