Zum Hauptinhalt springen

raygeo.svg.length

SVG length parsing and unit conversion.

Parses SVG length strings such as '10mm' or '2.5in' and converts between millimetres, pixels and other CSS units.

Functions

parse_svg_length()

parse_svg_length(length_str: str) -> tuple[float, str]

Parse an SVG length string into a (value, unit) tuple.

Supports: mm, cm, in, pt, pc, px. Unitless values default to 'px'.

ParameterTypeDescription
length_strstrSVG length string (e.g. '10mm', '2.5in', '100').
Returnstuple[float, str]Tuple of (value, unit).
ComplexityO(1)

svg_length_to_mm()

svg_length_to_mm(length_str: str, dpi: float = 96) -> float

Parse an SVG length string and convert to millimetres.

ParameterTypeDescription
length_strstrSVG length string (e.g. '10mm', '2.5in', '100').
dpifloat = 96Pixels per inch used for px/unitless conversion (default 96).
ReturnsfloatLength in millimetres.
ComplexityO(1)

svg_length_to_px()

svg_length_to_px(length_str: str, dpi: float = 96) -> float

Parse an SVG length string and convert to pixels.

ParameterTypeDescription
length_strstrSVG length string (e.g. '10mm', '2.5in', '100').
dpifloat = 96Pixels per inch used for px/unitless conversion (default 96).
ReturnsfloatLength in pixels.
ComplexityO(1)