Skip to content

Add support for SVG 2 viewport and root-relative units: rem, vw, vh, vmin, vmax, q #449

@deeplook

Description

@deeplook

Summary

svglib does not implement the CSS/SVG 2 length units introduced after SVG 1.1.
These units are increasingly common in modern SVG content.

Missing units

Unit Meaning Resolution strategy
rem Root element font-size Capture root font-size during render and use as rem base
vw 1% of viewport width Resolve against main_box.width (already tracked)
vh 1% of viewport height Resolve against main_box.height (already tracked)
vmin Smaller of vw and vh min(vw, vh)
vmax Larger of vw and vh max(vw, vh)
q Quarter-millimetre (0.25 mm) Straightforward physical conversion

ch is already approximated as 0.5em.

Notes

  • vw/vh should treat the outermost SVG canvas as the viewport (the PDF
    render target has no browser viewport).
  • rem requires storing the computed root font-size on Svg2RlgAttributeConverter
    before the tree walk begins.
  • The convertLength method in Svg2RlgAttributeConverter already has the
    right structure to add these as new elif branches.
  • Target: 2.1 (after 2.0 coordinate-system change stabilises).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions