fontmesh-0.3.0 has been yanked.
fontmesh
A fast Rust library for converting TrueType font glyphs to 2D and 3D triangle meshes. Providing a faster, pure rust alternative for ttf2mesh
Quick Start
use Font;
// Load font
let font = from_bytes?;
// Generate a 2D mesh (default: 20 subdivisions per curve)
let mesh_2d = font.glyph_to_mesh_2d?;
// Generate a 3D mesh with custom quality (50 subdivisions per curve)
let mesh_3d = font.glyph_by_char?
.with_subdivisions
.to_mesh_3d?;
API
fontmesh provides a chainable API that works at different levels of abstraction:
// High-level: One-step mesh generation (uses default: 20 subdivisions)
let mesh = font.glyph_to_mesh_3d?;
// Mid-level: Chain operations with custom subdivisions
let mesh = font.glyph_by_char?
.with_subdivisions
.to_mesh_3d?;
// Low-level: Access intermediate pipeline stages
let glyph = font.glyph_by_char?;
let outline = glyph.linearize?; // Uses default subdivisions
let mesh_2d = outline.triangulate?;
let mesh_3d = mesh_2d.extrude?;
Performance
fontmesh is 2-3x faster than comparable libraries, with the incredible Lyon.
Run benchmarks yourself: cargo bench --all-features
Examples
# Basic usage
# Chainable API examples
# Export glyphs to OBJ format
Pipeline
The mesh generation pipeline consists of the following stages:
- Font Loading - Parse TrueType fonts with ttf-parser
- Outline Extraction - Get glyph Bezier curves
- Linearization - Convert curves to line segments using adaptive subdivision
- Triangulation - Generate 2D triangle mesh with lyon_tessellation
- Extrusion - Create 3D mesh with depth and smooth normals
Each stage can be accessed individually, allowing you to:
- Export vector outlines for SVG/PDF rendering
- Reuse 2D meshes for multiple extrusion depths
- Apply custom post-processing (e.g.,
compute_smooth_normals) - Implement custom rendering pipelines
License
MIT