MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _svg_length_to_px

Function _svg_length_to_px

SLiCAP/schematic/export.py:48–64  ·  view source on GitHub ↗

Parse SVG length and convert to CSS pixels (96 dpi). SVGs with physical units (mm, cm, in, pt) but no viewBox use pixel coordinates internally; the width/height attributes only specify the physical rendered size. Converting to px gives the correct viewport size to use as the scale

(s, fallback: float)

Source from the content-addressed store, hash-verified

46
47
48def _svg_length_to_px(s, fallback: float) -> float:
49 """Parse SVG length and convert to CSS pixels (96 dpi).
50
51 SVGs with physical units (mm, cm, in, pt) but no viewBox use pixel
52 coordinates internally; the width/height attributes only specify the
53 physical rendered size. Converting to px gives the correct viewport
54 size to use as the scale denominator when inlining the SVG.
55 """
56 m = _SVG_LENGTH_RE.match(str(s)) if s else None
57 if m:
58 try:
59 val = float(m.group(1))
60 unit = (m.group(2) or 'px').lower()
61 return val * _UNIT_TO_PX.get(unit, 1.0)
62 except ValueError:
63 pass
64 return fallback
65
66
67def export_bounds(scene) -> QRectF:

Callers 1

_inline_image_svgFunction · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected