Expand description
The SVG subsystem: parse SVG documents and rasterize them to pixels.
Documents parse into a usvg::Tree — an immutable, Send + Sync
simplified scene graph — and rasterize CPU-side via resvg onto the
same tiny-skia Pixmap type the crate::canvas
module paints, so SVG output plugs into the existing “an image we paint
into” ImageNode plumbing without touching
Bevy’s render internals. Like canvas, this is a leaf module: the bridge
machinery reaches into crate::svg, never the reverse.
Licensing note: resvg/usvg were historically MPL-2.0, but as of the
linebender-maintained releases (0.47 included) they are dual-licensed
MIT OR Apache-2.0 — no license caveat applies.
Structs§
- Path
Data - A parsed
dattribute: the normalized segment list (possibly empty — an emptydstring is a valid, paint-nothing path). - Shape
Attrs - The folded attribute object of one SVG shape child (
<circle>,<rect>,<line>,<polyline>,<polygon>,<path>,<g>, …). All-Option: absent means “attribute not set”, and the shape kind decides which fields it reads. On update the whole object replaces atomically (seecrate::protocol::props::Props::merge_delta). - Shape
Transform - An SVG transform list resolved to a 2D affine, in SVG matrix order
[a, b, c, d, e, f]:x' = a·x + c·y + e,y' = b·x + d·y + f. - Shape
Transition Spec - The shape
transitionspec: per-attr easing timing, keyed by the [NUMERIC_ATTRS] wire names (shapes have nostyle, so the spec rides the shape object itself — noallfallback, no non-numeric channels). Entries are stored positionally in [NUMERIC_ATTRS] order; reuse of [ChannelTransition] (the style-transition timing type) is verbatim — same wire shape (duration/easing/delay/springs), same driver. - SvgAsset
Loader - Loads
.svgfiles intoSvgDocumentassets viaparse_svg_bytes. - SvgDocument
- A parsed SVG document: the resolution-independent scene graph, rasterized per node at laid-out size by the consumers of this asset.
- SvgParse
Error - The document failed to parse as SVG. Wraps
usvg::Error, which already covers non-UTF-8 input, malformed gzip, and XML parse failures —usvg::Tree::from_datahandles all of those itself. - SvgShape
- One shape child of a JSX
<svg>element: a Node-less entity (thetextSpanprecedent — no layout box, no style, nostamp_common) carrying only its kind and folded attrs. The rasterizer walks the<svg>root’sChildrento paint these, and the hit-tester reads the same data. Updates rewriteattrscompare-before-write, soChanged<SvgShape>is a sound dirt signal for the raster. - SvgSurface
- The element-owned raster surface of a node that displays an SVG.
- SvgUser
Pos - The cursor in the enclosing
<svg>root’s user space while a pointer hovers this shape;Nonewhile not hovered. Written by [sync_shape_interactions]; stamped/removed alongside the shape’s handler components (seereconcile::svg_ops). The position lives in an interiorOption(rather than inserting/removing the component per hover flip) so a hover boundary never causes archetype churn. - ViewBox
- The
<svg>element’sviewBox: the user-unit rectangle mapped onto the element’s layout box.
Enums§
- Fill
Rule Kind fill-rulekeyword.- Linecap
Kind stroke-linecapkeyword.- Linejoin
Kind stroke-linejoinkeyword.- PathSeg
- One normalized path segment. Coordinates are always absolute, in the SVG
user-unit space of the enclosing
<svg>’sviewBox. - Shape
Kind - The kind of a JSX SVG shape child: which wire intrinsic (
<circle>,<rect>, …,<g>) spawned it, and therefore whichShapeAttrsfields the rasterizer reads. - Shape
Paint - A resolved SVG paint: the explicit
"none"keyword (don’t paint — the web meaning offill="none", distinct from an absent paint, which uses the SVG defaults: fill black, stroke none) or a CSS color.
Functions§
- parse_
svg_ bytes - Parse raw SVG bytes (plain or gzip-compressed) into an
SvgDocument. All parsing logic lives here; the asset loader only feeds it file bytes. - rasterize_
document - Rasterize
docinto aw×hpixmap with the web’s<img>behavior for SVG sources: uniform scale,xMidYMid meetcentering — the document’s intrinsic aspect is letterboxed into the target box, never stretched.Noneon a zero-sized target. - stamp_
svg_ measures - Re-stamp the svg intrinsic measure after
bevy_uimay have cleared it. - update_
svg_ surfaces - Repaint every svg surface whose raster is stale — a repaint request
(
dirty), a layout resize, a document load/hot-reload (file mode), or a shape/child-list change (JSX mode, derived below) — and upload the result into the backing image. Reads the node’s size fromComputedNode(already physical px, so HiDPI rasters crisp); a freshly-mounted node has no size yet and rasters next frame, once layout ran.