thorvg 0.1.1

Safe Rust bindings to the ThorVG vector graphics library
Documentation
  • Coverage
  • 54.49%
    85 out of 156 items documented2 out of 5 items with examples
  • Size
  • Source code size: 176.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.87 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 29s Average build duration of successful builds.
  • all releases: 30s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • goyox86/thorvg-rs
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • goyox86

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 thorvg::{Thorvg, SwCanvas, Shape, ColorSpace};

let _engine = Thorvg::init(0).unwrap();

let mut canvas = SwCanvas::new(Default::default()).unwrap();
let mut buffer = vec![0u32; 800 * 600];
canvas.set_target(&mut buffer, 800, 800, 600, ColorSpace::ABGR8888).unwrap();

let mut shape = Shape::new();
shape.append_rect(10.0, 10.0, 200.0, 150.0, 10.0, 10.0, true).unwrap();
shape.set_fill_color(255, 0, 0, 255).unwrap();

canvas.push(shape).unwrap();
canvas.draw(true).unwrap();
canvas.sync().unwrap();
// buffer now contains rendered pixels

Features

  • std (default) — Adds file I/O APIs that accept std::path::Path
  • vendored (default, thorvg-sys) — Builds ThorVG from source via the vendored git submodule

Disable default features for no_std + alloc environments:

[dependencies]
thorvg = { version = "0.1", default-features = false }

API Coverage

100% of the ThorVG C API surface (158 functions) is wrapped:

  • CanvasSwCanvas, 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

cargo run --example shapes
cargo run --example stroke
cargo run --example gradient
cargo run --example scene
cargo run --example transforms
cargo run --example blending
cargo run --example opacity
cargo run --example clipping
cargo run --example masking
cargo run --example scene_effects
cargo run --example paths
cargo run --example picture_svg
cargo run --example paint_order
cargo run --example render_to_buffer

All examples output PNG files in the current directory.

Building

ThorVG is vendored as a git submodule and built automatically. You need meson and ninja installed:

# Debian/Ubuntu
sudo apt install meson ninja-build

# Fedora
sudo dnf install meson ninja-build

# macOS
brew install meson ninja

# pip
pip install meson ninja

Then:

git clone --recurse-submodules https://github.com/user/thorvg-rs
cd thorvg-rs
cargo build

Development

Requires just for task running:

just ci-quick    # fmt, clippy, test, no_std check
just ci          # full CI: above + AddressSanitizer + ThreadSanitizer
just test-asan   # run tests under AddressSanitizer
just examples    # run all 14 examples
just coverage    # show C API coverage stats
just --list      # show all recipes

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.