fontmesh
Library for converting font glyphs to 2D and 3D triangle meshes. A faster, pure Rust alternative to ttf2mesh.
Font parsing is handled by skrifa, so both TrueType (glyf) and OpenType with CFF/PostScript outlines are supported, and the same parsed-font handle plugs straight into shaping libraries like cosmic-text.
Quick Start
use ;
let font_data = include_bytes!;
let font = parse_font?;
let gid = glyph_id.expect;
// 2D mesh with 20 subdivisions per curve
let mesh_2d = glyph_to_mesh_2d?;
// 3D mesh with depth 0.1 em and 50 subdivisions
let mesh_3d = glyph_to_mesh_3d?;
Output coordinates are normalised to 1.0 em — depth = 0.1 is 10 % of the font's em square.
Working with a shaper
If you already have a skrifa::FontRef or skrifa::GlyphId from a shaper (cosmic-text, harfbuzz, …), pass it straight in — no extra parse is needed:
use ;
let font: FontRef = /* from your shaper */;
let gid: GlyphId = /* from your shaper */;
let mesh = glyph_to_mesh_3d?;
Examples
Performance
fontmesh is 2-3x faster than comparable libraries.
Run benchmarks: cargo bench
License
Licensed under either of MIT or Apache-2.0 at your option.