A library to parse and render SVG documents.
Render with the (optional) built-in Vello integration, or implement the RenderSink trait to bring your own renderer.
Warning
The goal of this crate is to provide decent coverage of the (large) SVG spec, up to what vello will support, for use in interactive graphics. If you are looking for a correct SVG renderer, see resvg. See vello for more information about limitations.
| vello_svg | vello | usvg | image |
|---|---|---|---|
| 0.11, main | 0.10 | 0.48 | - |
| 0.10 | 0.9 | 0.46 | 0.25 |
| 0.9 | 0.7 | 0.46 | 0.25 |
| 0.8 | 0.6 | 0.45 | 0.25 |
| 0.7 | 0.5 | 0.45 | 0.25 |
| 0.6 | 0.4 | 0.44 | 0.25 |
| 0.5 | 0.3 | 0.44 | 0.25 |
| 0.4 | 0.3 | 0.43 | 0.25 |
| 0.3 | 0.2 | 0.42 | 0.25 |
| 0.2 | 0.1 | 0.41 | 0.25 |
| 0.1 | 0.1 | 0.40 | 0.24 |
These examples target a local checkout of the development version.
If your backend doesn't use Vello, disable default features:
vello_svg = { path = "path/to/vello_svg", default-features = false }Implement RenderSink using the re-exported kurbo and peniko types, then call append(&mut sink, svg) or append_tree(&mut sink, &tree).
Raster images require a custom RenderSink::draw_image implementation for decoding and rendering. See ImageSink for a Vello wrapper using the image crate. Embedded SVG images render as vectors.
The vello feature is enabled by default:
vello_svg = { path = "path/to/vello_svg" }let svg = r#"<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<circle cx="50" cy="50" r="40" fill="red"/>
</svg>"#;
let scene = vello_svg::render(svg).expect("valid SVG");render_tree(&tree): create a scene from a parsedusvg::Tree.append(&mut scene, svg)/append_tree(&mut scene, &tree): add to an existing scene.- Enable
wgpufor Vello's GPU renderer.
The built-in backend skips raster images.
cargo run -p with_winitYou can also load an entire folder or individual files.
cargo run -p with_winit -- examples/assetsImageSink wraps Vello with image decoding, caching, and decode-error reporting. The viewer uses it for SVG files:
cargo run -p with_winit -- examples/assets/raster_image.svgBecause Vello relies heavily on compute shaders, we rely on the emerging WebGPU standard to run on the web. Until browser support becomes widespread, it will probably be necessary to use development browser versions (e.g. Chrome Canary) and explicitly enable WebGPU.
This uses cargo-run-wasm to build the example for web, and host a local server for it
# Make sure the Rust toolchain supports the wasm32 target
rustup target add wasm32-unknown-unknown
# The binary name must also be explicitly provided as it differs from the package name
cargo run_wasm -p with_winit --bin with_winit_binThere is also a web demo available here on supporting web browsers.
Warning
The web is not currently a primary target for Vello, and WebGPU implementations are incomplete, so you might run into issues running this example.
This version of Vello SVG has been verified to compile with Rust 1.88 and later.
Future versions of Vello SVG might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.
Click here if compiling fails.
As time has passed, some of Vello SVG's dependencies could have released versions with a higher Rust requirement. If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency.
# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1Discussion of Vello SVG development happens in the Linebender Zulip, specifically the #vello channel. All public content can be read without logging in.
Contributions are welcome by pull request. The Rust code of conduct applies.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option
The files in subdirectories of the examples/assets directory are licensed solely under
their respective licenses, available in the LICENSE file in their directories.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.