开发者

SVG 1.1 : What is "user unit" and how to convert user unit into absolute unit(eg: millimeter)?

开发者 https://www.devze.com 2023-03-28 09:25 出处:网络
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\", \

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. valu开发者_Go百科eAsString 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,


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消