Expand description
§fontmesh
Convert font glyphs to 2D and 3D triangle meshes.
This crate provides a small, stateless API for tessellating glyph outlines
into triangle meshes. Font parsing is handled by skrifa, so both
TrueType (glyf) and CFF/PostScript (CFF/CFF2) outlines are supported,
and the same parsed-font handle plugs straight into shaping libraries like
cosmic-text.
§Quick start
ⓘ
use fontmesh::{parse_font, glyph_id, glyph_to_mesh_3d};
let font_data = include_bytes!("path/to/font.ttf");
let font = parse_font(font_data)?;
let gid = glyph_id(&font, 'A').expect("font has 'A'");
let mesh = glyph_to_mesh_3d(&font, gid, 0.1, 20)?;§API surface
- Parsing:
parse_fontreturns askrifa::FontRef. It’s also exposed directly asFontRefif you want to skip the wrapper. - Glyph IDs:
glyph_idresolves achar→GlyphId. If you’re driving fontmesh from a text shaper you already have these IDs and can skip the lookup. - Meshes:
glyph_to_mesh_2d/glyph_to_mesh_3dor the fluentGlyphMeshBuilder. - Metrics:
ascender,descender,line_gap,advance,glyph_advance— all normalised to 1.0 em.
§Pipeline
- Parse the font (
FontRef::from_index) - Extract the glyph outline (skrifa
OutlinePen) - Linearise curves (
linearize_outline) - Triangulate ([
triangulate]) - Optionally extrude to 3D ([
extrude])
Each stage is exposed publicly so advanced callers can plug their own glyph source in at step 3.
Re-exports§
pub use error::FontMeshError;pub use error::Result;pub use extrude::compute_smooth_normals;pub use extrude::extrude;pub use font::advance;pub use font::ascender;pub use font::descender;pub use font::glyph_advance;pub use font::glyph_id;pub use font::line_gap;pub use font::parse_font;pub use glyph::glyph_to_mesh_2d;pub use glyph::glyph_to_mesh_3d;pub use glyph::GlyphMeshBuilder;pub use linearize::linearize_outline;pub use triangulate::triangulate;pub use types::Mesh2D;pub use types::Mesh3D;pub use types::Outline2D;
Modules§
- error
- Error types for fontmesh
- extrude
- 3D extrusion - converts 2D meshes to 3D with depth
- font
- Font parsing utilities
- glyph
- Glyph outline extraction and tessellation.
- linearize
- Curve linearization - converts Bezier curves to line segments
- triangulate
- 2D triangulation using lyon_tessellation
- types
- Core type definitions for fontmesh
Structs§
Traits§
- Metadata
Provider - Interface for types that can provide font metadata.