Skip to main content

Module svg

Module svg 

Source
Expand description

SVG export backend.

SvgRenderer implements the Renderer trait, so the exact same render path that draws the diagram on screen can be pointed at it to produce a standalone .svg. Geometry has a single source of truth; this module only translates the primitive calls into SVG nodes (built with the svg crate). Like the on-screen painter it holds a Palette and resolves each Swatch to a color at draw time — the canvas never sees an app-level role.

Text layout comes from the host’s TextLayout — the very engine that lays the diagram out on screen — so the rows a run breaks into, and where each row stands, are the screen’s. Each row is written as a <text> in the face’s own family, with the face embedded, so the export’s text is text: a viewer can select it, a PDF made from it carries it, a search finds it. The viewer shapes within a row; the row is ours.

Coordinates are world space and written out directly (no zoom/pan); the final <svg viewBox> frames whatever was drawn.

Structs§

Ink 🔒
A palette stroke resolved to what the SVG states: a width and a color.
SvgRenderer

Functions§

apply_fill 🔒
apply_stroke 🔒
Set stroke/stroke-width(+opacity); no-op when there’s no visible stroke.
color_hex 🔒
fill 🔒
fill/fill-opacity, or fill="none" when fully transparent.
font_face 🔒
The @font-face rule that embeds bytes under family, so a viewer without the face installed sets the text in it.
framed 🔒
The world rect an export frames: everything drawn, and a cell’s margin around it — or a unit square for a level that drew nothing.
point_list 🔒
Build the points attribute value for a polyline/polygon. Vec<(f32, f32)> serializes to "x y x y …", which SVG accepts.
text_element 🔒
One row as a <text> at its pen, turned about it by angle. Written by hand because the svg crate breaks an element’s content onto lines of its own, which xml:space="preserve" would set as spaces.