Skip to main content

Crate fontmesh

Crate fontmesh 

Source
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

§Pipeline

  1. Parse the font (FontRef::from_index)
  2. Extract the glyph outline (skrifa OutlinePen)
  3. Linearise curves (linearize_outline)
  4. Triangulate ([triangulate])
  5. 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§

FontRef
Reference to an in-memory font.
GlyphId
A 32-bit glyph identifier.

Traits§

MetadataProvider
Interface for types that can provide font metadata.