Expand description
Safe, idiomatic Rust bindings to the ThorVG vector graphics library.
ThorVG is a production-ready vector graphics engine supporting SVG, Lottie animations,
shapes, text, gradients, effects, and more.
§no_std Support
This crate is no_std compatible (requires alloc). The std feature (enabled by default)
adds file I/O APIs that accept std::path::Path (e.g., Picture::load, Text::load_font).
To use in no_std, disable default features:
[dependencies]
thorvg = { version = "0.1", default-features = false }§Quick Start
use thorvg::{Thorvg, SwCanvas, Shape, ColorSpace};
// Initialize the engine
let _guard = Thorvg::init(0).expect("Failed to initialize ThorVG");
// Create a canvas with a buffer
let mut canvas = SwCanvas::new(Default::default()).expect("Failed to create canvas");
let mut buffer = vec![0u32; 800 * 600];
// Safety: buffer outlives the canvas.
unsafe {
canvas
.set_target(&mut buffer, 800, 800, 600, ColorSpace::ABGR8888)
.expect("Failed to set target");
}
// Draw a red rectangle
let mut shape = Shape::new();
shape.append_rect(0.0, 0.0, 200.0, 200.0, 0.0, 0.0, true);
shape.set_fill_color(255, 0, 0, 255).unwrap();
canvas.push(shape).unwrap();
// Render
canvas.draw(true).unwrap();
canvas.sync().unwrap();Structs§
- Accessor
- Scene tree traversal helper.
- Animation
- An animation controller for animated content (e.g., Lottie).
- Color
Stop - A color stop in a gradient.
- GlCanvas
- An OpenGL/ES-rendered canvas.
- Glyph
Metrics - Layout metrics of a glyph.
- Linear
Gradient - A linear gradient fill.
- Lottie
Animation - A Lottie animation controller with Lottie-specific extensions.
- Marker
- Marker information for a Lottie animation segment.
- Matrix
- A 3×3 affine transformation matrix.
- Picture
- A picture object for loading and displaying images (SVG, PNG, JPG, Lottie, etc.).
- Point
- A point in 2D space.
- Radial
Gradient - A radial gradient fill.
- Saver
- Exports paint objects or animations to files.
- Scene
- A scene that groups multiple paint objects.
- Shape
- A two-dimensional shape with path, fill, and stroke properties.
- SwCanvas
- A software-rendered canvas.
- Text
- A text object for rendering unicode text.
- Text
Metrics - Font metrics for a text object.
- Thorvg
- RAII guard for the
ThorVGengine lifetime. - WgCanvas
- A WebGPU-rendered canvas.
Enums§
- Blend
Method - Blending method for compositing paint objects.
- Color
Space - Color space for the rendering buffer.
- Engine
Option - Engine rendering options.
- Error
- Errors returned by
ThorVGoperations. - Fill
Rule - Fill rule for determining the interior of a shape.
- Fill
Spread - How to fill the area outside the gradient bounds.
- Filter
Method - Image filtering method used during scaling or transformation.
- Mask
Method - Masking method for combining two paint objects.
- Paint
Type - The concrete type of a paint object.
- Stroke
Cap - Stroke line cap style.
- Stroke
Join - Stroke line join style.
- Text
Wrap - Text wrapping mode.
- WgTarget
Type - WebGPU target type.
Traits§
- Paint
- Common trait for all paint objects (Shape, Scene, Picture, Text).
Type Aliases§
- Result
- Result type for
ThorVGoperations.