lievisual
Declarative visual scene IR with pluggable rendering backends.
Upper layers (charts / diagrams / documents) declare what to draw as a Scene;
backends decide how — SVG, CPU-rasterized PNG, or (planned) GPU.
- Pure Rust, edition 2024, no unsafe; every backend enabled by default, no feature gates
- One IR, two backends with a single sizing contract: the size given to a renderer is the
output size —
scaleis a pure density knob, never a silent enlargement - Text API mirrors Web Canvas (
textAlign/textBaseline/measureText), so browser experience ports over
Usage
[]
= "0.2"
use ;
use SvgRenderer;
use ;
let mut scene = new.with_background;
scene.push;
scene.push;
// SVG
let mut svg = new;
scene.render;
let svg_str = svg.into_string;
// PNG
let mut raster = new
.with_background;
let png: = raster.render_png;
A richer tour (layers, gradients, pie, canvas-style builder, both outputs):
Highlights
- Canvas-like builder —
Ctx+Path2Dcover the Canvas 2D vocabulary (fillRect,beginPath…fill(), transform/alpha/clip) plus what Canvas lacks: layers, named nodes, rich-text spans, gradients as fills, dash/cap/join. Immutable (with_*chains), and every method returns inspectable IR. - Layers & node attributes —
z_index/ transform / clip / opacity /name/visiblelive once onSceneNode; layers stack bottom-to-top with whole-layer attributes. - Content bounds & auto-fit —
fit::scene_bounds+fit_scene(&mut scene, FitOptions)hug the canvas to the content (stroke widths, node transforms and text rotation included); built for "content-driven canvas" exporters. - Rich primitives — rects, circles, ellipses (rotatable), rounded rects, lines, polylines, polygons, arcs, pies, paths, gradient paths, images, groups; solid/linear/radial fills, dashes, caps, joins, miter limit; clips consistent across backends.
- Cross-backend text — glyphs typeset once (parley) into a shared
TextLayout; the SVG backend emits native<text>, the raster backend renders the layout.register_fontis process-wide, visible to all threads.
Backends
| Backend | Output | Text |
|---|---|---|
SvgRenderer |
SVG string | Native <text> (browser typesets) |
VelloPixmapRenderer |
Pixmap → PNG |
parley layout |
GPU (vello_hybrid) |
planned | — |
Layout
src/
geometry.rs Point / Rect / Color / Transform (f64, kurbo-aligned)
scene.rs Scene / Layer / SceneNode / Element / styles / Clip
text/ Canvas-style text API + parley-backed layout engine
builder.rs Ctx + Path2D (Canvas 2D superset)
fit.rs content bounds + fit_scene
render/ Renderer trait, SvgRenderer, VelloPixmapRenderer
pixmap.rs self-contained RGBA8 bitmap + PNG encode/decode
Testing
License
Licensed under either of
at your option.