Skip to main content

Module svg

Module svg 

Source
Expand description

SVG support shared by the inline <svg> painter and the standalone rasterizer.

§Inline SVG

The layout builder calls collect_svg while building the node for an <svg> element. The renderer then paints the collected shapes into the element’s content box via emit_commands, mapping the viewBox rectangle onto the box with viewbox_meet_transform (xMidYMid meet, the SVG default).

§Standalone SVG documents

Audio icons and <img src="*.svg"> are rasterized to RGBA pixels by rasterize_from_bytes, which replaces the removed resvg dependency.

Coverage stays focused on solid-color fills: <path d> (including arc segments, expanded into cubic Béziers), <rect>, <circle>, <ellipse>, container <g>/<a>/<symbol> with composed transform/opacity attributes, fill-rule, and opacity/fill-opacity (approximated as a per-shape alpha multiplier). <use>/<clipPath>/gradients, strokes, and text are out of scope.

Structs§

ClipPath
A clipping path: a viewBox-space path plus its fill rule, used to mask shapes that reference it via clip-path="url(#id)".
RasterResult
Decoded RGBA8 pixels plus the rasterized viewport dimensions.
SvgContent
The vector content of an crate::engine::layouter::types::NodeKind::Svg layout node: the element’s viewBox and its subpaths in document order.
SvgShape
A single shape inside an inline SVG: a viewBox-space path, its paint (solid color or gradient), and the fill rule (default nonzero). stroke is None when the shape has no stroke. clip_path optionally references a clip path that masks this shape.
SvgStroke
A resolved SVG stroke: paint color plus the geometry parameters that stroke_path expands the outline with. When gradient is set it paints the outline instead of color.

Functions§

collect_svg
Collects the inline SVG content of an <svg> element: its viewBox and the solid-color shapes of its content, recursively.
emit_commands
Paints the shapes of an inline SVG into its content box.
parse_view_box
Parses an SVG viewBox attribute into (min-x, min-y, width, height), defaulting missing components to zero.
path_from_d
Translates an SVG path d string into a Path.
rasterize_from_bytes
Parses SVG bytes and rasterizes them to straight-alpha RGBA pixels.
viewbox_meet_transform
Builds the transform mapping viewBox coordinates into a viewport using xMidYMid meet (the SVG default: fit the whole box inside the viewport, centered). Without a usable viewBox, coordinates map 1:1.

Type Aliases§

ViewBox
An SVG viewBox rectangle: (min-x, min-y, width, height).