pub struct Font<'a> { /* private fields */ }Expand description
A loaded TrueType font
Implementations§
Source§impl<'a> Font<'a>
impl<'a> Font<'a>
Sourcepub fn from_bytes(data: &'a [u8]) -> Result<Self>
pub fn from_bytes(data: &'a [u8]) -> Result<Self>
Sourcepub fn glyph_by_char(&self, c: char) -> Result<Glyph<'_>>
pub fn glyph_by_char(&self, c: char) -> Result<Glyph<'_>>
Sourcepub fn glyph_by_id(&self, glyph_id: GlyphId, character: char) -> Glyph<'_>
pub fn glyph_by_id(&self, glyph_id: GlyphId, character: char) -> Glyph<'_>
Get a glyph by its glyph ID
This is useful when working with text shaping libraries or when you
already have glyph IDs from other sources (e.g., rustybuzz, cosmic-text).
§Arguments
glyph_id- The glyph ID to look upcharacter- The character this glyph represents (for display purposes)
§Returns
A glyph with metrics and outline information
§Example
ⓘ
use ttf_parser::GlyphId;
let glyph_id = GlyphId(42);
let glyph = font.glyph_by_id(glyph_id, 'A');Sourcepub fn face(&self) -> &Face<'a>
pub fn face(&self) -> &Face<'a>
Access the underlying ttf-parser Face for advanced operations
This allows you to use any ttf-parser functionality directly, such as accessing font tables, kerning information, or other font metadata that fontmesh doesn’t expose.
§Example
ⓘ
// Get kerning between two glyphs
let face = font.face();
let kern = face.kerning_subtables();
// Access font name
for name in face.names() {
println!("{:?}: {}", name.name_id, name.to_string());
}Sourcepub fn units_per_em(&self) -> u16
pub fn units_per_em(&self) -> u16
Get the font’s units per em
Source§impl<'a> Font<'a>
impl<'a> Font<'a>
Sourcepub fn glyph_to_mesh_2d(&self, character: char) -> Result<Mesh2D>
pub fn glyph_to_mesh_2d(&self, character: char) -> Result<Mesh2D>
Sourcepub fn glyph_to_mesh_3d(&self, character: char, depth: f32) -> Result<Mesh3D>
pub fn glyph_to_mesh_3d(&self, character: char, depth: f32) -> Result<Mesh3D>
Convert a character glyph to a 3D triangle mesh with extrusion
Uses default quality (20 subdivisions per curve).
§Arguments
character- The character to convertdepth- The extrusion depth
§Returns
A 3D triangle mesh with normals
§Example
ⓘ
let mesh = font.glyph_to_mesh_3d('A', 5.0)?;
println!("Generated {} triangles", mesh.triangle_count());Auto Trait Implementations§
impl<'a> Freeze for Font<'a>
impl<'a> RefUnwindSafe for Font<'a>
impl<'a> Send for Font<'a>
impl<'a> Sync for Font<'a>
impl<'a> Unpin for Font<'a>
impl<'a> UnwindSafe for Font<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more