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 = 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)?;
assert!(!mesh.is_empty());§Coordinate system
All output coordinates are normalised to 1.0 em. (0, 0) is the glyph
origin (typically the left side of the baseline), +X points right, and +Y
points up. Extrusion depth is also in em units — depth = 0.1 is 10 % of
the em square. Front faces sit at z = +depth/2, back faces at
z = -depth/2.
§Quality (subdivisions)
The subdivisions argument controls how finely Bézier curves are sampled
before triangulation. 20 is a good default; higher values produce
smoother curves at the cost of more vertices. 0 is rejected as
FontMeshError::InvalidQuality.
§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 returned by fontmesh operations.
- extrude
- 3D extrusion — converts 2D meshes to 3D with depth.
- font
- Font parsing and em-normalised metrics.
- glyph
- Glyph outline extraction and tessellation.
- linearize
- Curve linearization — converts Bézier curves to line segments.
- triangulate
- 2D triangulation using
lyon_tessellation. - types
- Mesh, outline, and contour types used throughout fontmesh.
Structs§
Traits§
- Metadata
Provider - Interface for types that can provide font metadata.