9

I am implementing SVG Tiny 1.1 and I am having trouble understanding the "user unit" concept.

SVG 1.1 specification defines every <length> with no specified unit (such as "mm", "cm", "pt", etc) to be in "user unit".

While implementing interface "SVGLength", I encountered 4 attributes related to the value of the length; value, unityType, valueInSpecifiedUnit, valueAsString. The last 3 attributes are clear enough for me.

  1. valueInSpecifiedUnit is in unit type unitType.
  2. valueAsString equals valueInSpecifiedUnit+unitType's string value. Eg: "10mm"

However, the attribute value is said to be in user unit. So my questions are:

  1. What is "user unit"?
  2. how to convert from "user unit" to an "absolute unit" such as millimeter (mm) ?

Regards,

David Andreoletti
  • 4,485
  • 4
  • 29
  • 51

1 Answers1

8

The spec says:

user units

A coordinate value or length expressed in user units represents a coordinate value or length in the current user coordinate system. Thus, 10 user units represents a length of 10 units in the current user coordinate system.

Also:

if the ‘width’ or ‘height’ attributes on the outermost svg element are in user units (i.e., no unit identifier has been provided), then the value is assumed to be equivalent to the same number of "px" units

which means that user units are the units specified in the outermost svg element's width and height attributes, and if they are not specified, then user units are pixels.

Read the section on units in SVG.

Spadar Shut
  • 15,111
  • 5
  • 47
  • 54
  • 7
    So the "user unit" is defined in outmost svg element's width and heigth attributes. Examples: then user unit is "cm". then user unit is "px". Is this right ? – David Andreoletti Aug 18 '11 at 03:17
  • 1
    And then, is there a implicit conversion between pixels and mm? Is there somewhere an asumption on the DPI used in SVG documents? "Resolution" so to speak, even if we're talking vector. – Ideogram Jul 01 '15 at 10:56
  • 5
    @DavidAndreoletti No, the user unit is always equal to one `px`. Per the spec: "One px unit is defined to be equal to one user unit." The other units are scaled relative to the size of a `px`, i.e. `1mm` is always equal to `3.543307px` and equal to just `3.543307`. – Feuermurmel Sep 29 '15 at 19:59
  • 2
    The ratio given of 3.543307px per mm equates to 90dpi which is what Inkscape used to use, but I believe the common standard these days is 96dpi or 3.779527559. The SVG standard seems to avoid linking the user units with physical units, so it very much depends on the resolution of the implementation - so OP it is up to you depending on the DPI you choose. – Kevin Sadler Jun 09 '17 at 14:35
  • I don't believe this answer is true. It seems me that if you specify the outer `` element's width and height in CM, the user units will be in CM. – Clonkex Jun 24 '21 at 05:01
  • Do the comments contradict the answer? It seems like these 3 statements cannot all be true: (1) “User units are the units specified in the outermost svg element's width and height attributes”, (2) “One px unit is defined to be equal to one user unit”, and (3) “1mm is always equal to 3.543307px”. – randy Jul 07 '22 at 20:33