font size reported incorrectly in XML editor when changing document units.

Bug #1394725 reported by Alvin Penner on 2014-11-20
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

- Windows XP, Inkscape rev 13709
- open Inkscape, open Document Properties, set default units to px.
- draw some text using F8
- in my case the default font size was 67.5 pt. in the toolbar at the top.
- open XML editor and note that the style property of the text says 'font-size:90px'
- these two statements are consistent with each other at 96 dpi.
- now change the default units to mm
- note that the XML editor reports the style property 'font-size:23.8125px'.
- this is wrong, it should be either 90px or 23.8125mm

- this is probably related to Bug 1248120, but not quite the same.

su_v (suv-lp) wrote :

On 2014-11-20 20:19 (+0100), Alvin Penner wrote:
> - open Inkscape, open Document Properties, set default units to px.
> - now change the default units to mm
> (…)
> - this is wrong, it should be either 90px or 23.8125mm

 Are you sure? Please check the viewBox attribute - changing the defaults units back to 'mm' in trunk should redefine the size of the SVG user unit ( 1 'px' (aka SVG user unit) now equals 1mm ).

What seems to be wrong is the size shown in the status bar when the text is selected.

See also:

tags: added: fonts units
Alvin Penner (apenner) wrote :

a pixel 'px' is still defined as being 96 'px' per inch regardless of what the view box says

su_v (suv-lp) wrote :

Sorry - please bring this up on the mailing list for discussion.

su_v (suv-lp) wrote :

To quote from the wiki page (by Inkscape's resident SVG expert):
«Absolute units (other than 'px' inside CSS) should not be used inside an SVG file with one exception:

The root width and height may have units, which with a proper viewBox determines an appropriate scale for a drawing. (This sets the "real" world value of the SVG user unit.) This reflect the opinion of the majority of the SVG working group.

In CSS a unit identifier must be present. As 'px' is defined in SVG to be the same as a user unit the following are equal: font-size="20" and style="font-size:20px". »

su_v (suv-lp) wrote :

… and from <>
«Changing the Document Unit changes the relationship between the width/height and viewBox such that the initial user unit (aka 'px') is equal to the Document Unit. »

LucaDC (dicappello) wrote :

IMHO px here is an inappropriate unit: either use pt or mm.
I see no point in discussing what a px is in a mm document.

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

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers