blinc_svg
Part of the Blinc UI Framework
This crate is a component of Blinc, a GPU-accelerated UI framework for Rust. For full documentation and guides, visit the Blinc documentation.
SVG loading and rendering for Blinc UI.
Overview
blinc_svg provides SVG parsing and rendering capabilities using usvg and resvg.
Features
- SVG Parsing: Full SVG support via usvg
- Two Render Modes:
- Tessellation: Fast, converts paths to triangles via Lyon
- Rasterization: High-quality CPU rendering via resvg
- Tinting: Apply color tints to SVGs
- Scaling: Render at any size
Quick Start
use SvgDocument;
// Load SVG from file
let svg = load?;
// Load from string
let svg = parse?;
// Get dimensions
let = svg.size;
Rasterization
use RasterizedSvg;
// Rasterize at specific size
let rasterized = svg.rasterize?;
// Get pixel data
let pixels = rasterized.pixels;
let width = rasterized.width;
let height = rasterized.height;
Usage in Layout
use *;
use icons;
// SVG from string
svg
.size
// SVG from icon constant
svg
.size
.color
// Custom SVG file
svg_file
.size
Tinting
// Apply solid color tint
svg
.size
.color
// SVGs are rendered with the tint color applied
// to all fill and stroke elements
Performance
For best performance:
- Use rasterization for complex SVGs displayed at fixed sizes
- Use tessellation for simple icons that scale dynamically
- Cache rasterized SVGs when displaying the same icon repeatedly
Architecture
blinc_svg
├── document.rs # SVG document parsing
├── rasterize.rs # CPU rasterization via resvg
├── tessellate.rs # Path tessellation via lyon
└── commands.rs # Drawing command generation
License
MIT OR Apache-2.0