Expand description
§Overview
A high-level Rust wrapper API for fetisov’s ttf2mesh
library for generating a 2d/3d mesh (vertices, indices and normals [only for 3D])
from TrueType (.ttf) glyphs.
Usage:
let mut ttf = TTFFile::from_file("./fonts/FiraMono-Medium.ttf").unwrap();
// export all glyphs as 2d meshes to a .obj file
ttf.export_to_obj("./fonts/FiraMono-Medium.obj", Quality::Low).unwrap();
// generate 2d mesh for a glyph
let mut glyph = ttf.glyph_from_char('€').unwrap();
let mesh_2d: Mesh<Mesh2d> = glyph.to_2d_mesh(Quality::Medium).unwrap();
// work with Mesh vertices, faces (indices). See Mesh documentation for more
assert_eq!(mesh_2d.vertices_len(), 56);
assert_eq!(mesh_2d.iter_vertices().next().unwrap().val(), (0.555, 0.656));
assert_eq!(mesh_2d.faces_len(), 54);
assert_eq!(mesh_2d.iter_faces().next().unwrap().val(), (53, 52, 5));
// 3d mesh with depth of 0.5
let mesh_3d: Mesh<Mesh3d> = glyph.to_3d_mesh(Quality::Medium, 0.5).unwrap();Structs§
- Data
Iterator - An iterator over an array of mesh values (separate output type for 2d vertices, 3d vertices, faces and normals)
- Glyph
- Represents a glyph in truetype font file. Can be converted to a 2d or 3d
Mesh - Mesh
- A (2d or 3d) mesh that has been generated from a
Glyph - TTFFile
- A decoded TTF file instance. Contains a list of
Glyph’s
Enums§
- Error
- Represents an error by the library
- Quality
- Quality of the output mesh. Higher quality produces more vertices and takes longer
Traits§
- Value
- Value produced by a mesh data iterator. Access with
.val()