plutovg-sys
FFI bindings to PlutoVG, a 2D vector graphics library written in C.
About PlutoVG
PlutoVG is a standalone 2D vector graphics library that provides:
- Vector path rendering
- Text rendering with font support
- Various paint types (solid colors, gradients, patterns)
- Transformations and clipping
- Export to PNG format
Features
- Raw FFI bindings to the complete PlutoVG C API
- Safe Rust constants for mathematical values (π, √2, etc.)
- Automatic building and linking of the PlutoVG C library
- Cross-platform support
Installation
Add this to your Cargo.toml:
[]
= "0.0.1"
Usage
This crate provides low-level FFI bindings. All functions are unsafe and require manual memory management.
Basic Example
use *;
use CString;
unsafe
Smiley Face Example
Run the included example to generate a smiley face:
This creates a smiley.png file with a yellow smiley face.
Constants
The crate provides mathematical constants as f32 values:
PLUTOVG_PI- π (3.141592...)PLUTOVG_TWO_PI- 2πPLUTOVG_HALF_PI- π/2PLUTOVG_SQRT2- √2PLUTOVG_KAPPA- κ (0.552284...)
Building
This crate uses bindgen to generate Rust bindings and cc to compile the PlutoVG C library. The build process:
- Compiles all PlutoVG C source files
- Generates Rust bindings from the C headers
- Links everything together
Requirements
- A C compiler (GCC, Clang, or MSVC)
- Rust 2024 edition
Safety
⚠️ All functions in this crate are unsafe
You must ensure:
- Proper initialization and cleanup of surfaces and canvases
- Valid pointer management
- Correct order of operations (create surface before canvas, etc.)
- No use-after-free errors
License
This project is licensed under the MIT License - see the LICENSE file for details.
The bundled PlutoVG library is also MIT licensed.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.