Skip to main content

Crate thorvg

Crate thorvg 

Source
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).
ColorStop
A color stop in a gradient.
GlCanvas
An OpenGL/ES-rendered canvas.
GlyphMetrics
Layout metrics of a glyph.
LinearGradient
A linear gradient fill.
LottieAnimation
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.
RadialGradient
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.
TextMetrics
Font metrics for a text object.
Thorvg
RAII guard for the ThorVG engine lifetime.
WgCanvas
A WebGPU-rendered canvas.

Enums§

BlendMethod
Blending method for compositing paint objects.
ColorSpace
Color space for the rendering buffer.
EngineOption
Engine rendering options.
Error
Errors returned by ThorVG operations.
FillRule
Fill rule for determining the interior of a shape.
FillSpread
How to fill the area outside the gradient bounds.
FilterMethod
Image filtering method used during scaling or transformation.
MaskMethod
Masking method for combining two paint objects.
PaintType
The concrete type of a paint object.
StrokeCap
Stroke line cap style.
StrokeJoin
Stroke line join style.
TextWrap
Text wrapping mode.
WgTargetType
WebGPU target type.

Traits§

Paint
Common trait for all paint objects (Shape, Scene, Picture, Text).

Type Aliases§

Result
Result type for ThorVG operations.