thorvg-rs
⚠️ Work in progress — This crate is under active development and not yet ready for production use. APIs may change without notice.
Rust bindings for ThorVG, a production-ready vector graphics engine supporting SVG, Lottie animations, shapes, text, gradients, effects, and more.
Crates
| Crate | Description |
|---|---|
thorvg-sys |
Raw FFI bindings generated by bindgen |
thorvg |
Safe, idiomatic Rust wrapper |
Quick Start
use ;
let _engine = init.unwrap;
let mut canvas = new.unwrap;
let mut buffer = vec!;
canvas.set_target.unwrap;
let mut shape = new;
shape.append_rect.unwrap;
shape.set_fill_color.unwrap;
canvas.push.unwrap;
canvas.draw.unwrap;
canvas.sync.unwrap;
// buffer now contains rendered pixels
Features
thorvg (safe wrapper)
| Feature | Default | Description |
|---|---|---|
std |
✅ | File I/O APIs (Picture::load, Text::load_font, etc.) |
vendored |
✅ | Build ThorVG from source via the cc crate |
lottie |
✅ | Lottie animation loader |
svg |
✅ | SVG loader |
png |
✅ | Built-in PNG loader (lodepng, no system dep) |
fonts |
✅ | SFNT / OTF / TTF font loaders |
expressions |
✅ | Lottie expressions via JerryScript (~200 KB RAM) |
threads |
✅ | Multi-threaded TaskScheduler (std::thread) |
file-io |
✅ | Filesystem I/O support in ThorVG |
All features are pass-throughs to thorvg-sys.
Desktop (default — everything enabled)
[]
= "0.1"
Embedded / no_std (pick only what you need)
[]
= { = "0.1", = false, = ["vendored", "lottie", "svg"] }
This gives you Lottie + SVG playback with no threads, no JerryScript, no PNG/font loaders — suitable for microcontrollers with limited RAM.
Cross-Compilation
ThorVG is compiled from C++ source using the cc crate, which
automatically picks up the correct cross-compiler from Cargo's target
environment. No meson or ninja required.
Tested targets:
| Target | Compiler | Notes |
|---|---|---|
x86_64-unknown-linux-gnu |
g++ / clang++ |
Desktop default |
xtensa-esp32s3-espidf |
xtensa-esp32s3-elf-g++ |
ESP32-S3 (Waveshare Knob Touch S3) |
xtensa-esp32-espidf |
xtensa-esp32-elf-g++ |
ESP32 |
riscv32imc-esp-espidf |
riscv32-esp-elf-g++ |
ESP32-C6 |
thumbv8m.main-none-eabihf |
arm-none-eabi-g++ |
RP2350 / Cortex-M33 |
For Xtensa targets, the build script automatically selects the correct
target-specific compiler wrapper (e.g. xtensa-esp32s3-elf-g++) to
ensure the right endianness and ABI.
API Coverage
100% of the ThorVG C API surface (158 functions) is wrapped:
- Canvas —
SwCanvas,GlCanvas,WgCanvas - Paint — opacity, visibility, transforms, clipping, masking, blending, hit-testing
- Shape — paths, rectangles, circles, fill, stroke, gradients, trim path
- Gradient — linear, radial, color stops, spread, transforms
- Picture — load SVG/PNG/JPG/WebP/Lottie from file or memory
- Scene — grouping, effects (blur, drop shadow, fill, tint, tritone)
- Text — font loading, styling, wrapping, metrics, outline
- Animation — frame control, segments, duration
- LottieAnimation — slots, markers, tweening, expressions, quality
- Saver — export paint/animation to file
- Accessor — scene tree traversal with callbacks
no_std Support
Both crates are no_std compatible. The safe wrapper requires alloc.
File I/O APIs (Picture::load, Text::load_font, Saver::save) are
gated behind the std feature. All rendering, shapes, gradients,
scenes, and canvas operations work in no_std.
Examples
All examples output PNG files in the current directory.
Building
ThorVG is vendored as a git submodule and compiled automatically via
the cc crate. You need a C++ compiler
(any g++ or clang++ will do):
No meson, ninja, or pkg-config required for vendored builds.
Development
Requires just for task running:
Acknowledgments
This project provides Rust bindings to ThorVG, created and maintained by the ThorVG project contributors. ThorVG is a Linux Foundation project. All vector graphics rendering is performed by the ThorVG engine — this crate is a thin binding layer.
This project is not affiliated with, endorsed by, or sponsored by the ThorVG project or the Linux Foundation.
Special thanks to Hermet Park and all ThorVG contributors for building such an excellent, lightweight, and well-designed vector graphics engine with a clean C API that made these bindings possible.
License
MIT — same as ThorVG.