Expand description
§LibYAFF: Yet Another Font Format Library
A Rust library for parsing, manipulating, and generating bitmap fonts in the YAFF format.
§Features
- Complete YAFF format support: Parse and generate YAFF 1.0.x format files
- Unicode and legacy encoding: Support for Unicode, codepoint, and tag-based glyph labeling
- Advanced typography: Kerning, bearing adjustments, and font metrics
- Robust parsing: Handles format variations and provides detailed error messages
- Memory efficient: Optimized for embedded and resource-constrained environments
§Quick Start
use libyaff::{YaffFont, to_yaff_string};
// Load a YAFF font from file
let font = YaffFont::from_path("my_font.yaff")?;
println!("Loaded font: {}", font.name.as_ref().unwrap_or(&"".to_string()));
// Access font metrics
if let Some(ascent) = font.ascent {
println!("Font ascent: {}", ascent);
}
// Convert back to YAFF format
let yaff_content = to_yaff_string(&font);
std::fs::write("output.yaff", yaff_content)?;
§Font Structure
A YAFF font consists of:
- Metadata: Font name, family, size, style information
- Metrics: Ascent, descent, line height, kerning data
- Glyphs: Individual character bitmaps with labels and metrics
§Error Handling
All parsing operations return Result<T, ParseError>
with detailed error information
including line numbers and context for debugging malformed YAFF files.
Structs§
- Bitmap
- Bitmap representation of a glyph as a 2D boolean array.
- Glyph
Definition - A single glyph definition including bitmap data and typography metrics.
- Yaff
Font
Enums§
- Font
Spacing - Label
- Glyph labeling system supporting Unicode, legacy codepoints, and custom tags.
- Line
Type - Parse
Error - Writing
Direction
Functions§
- calculate_
ascent - Calculate the ascent value for a font based on its glyphs
- classify_
line - Classifies a single line from a YAFF file. Returns a tuple of (line_type, indentation_level).
- convert_
codepoint_ to_ unicode_ labels - Convert Codepoint labels to Unicode labels for ASCII range
- minimize_
all_ bounding_ boxes - Minimize the bounding boxes of all glyphs in a font
- minimize_
glyph_ bounding_ box - Minimize the bounding box of a single glyph
- parse_
key_ as_ label - Parses a key string (content before the final ‘:’ of a label line)
into an
Option<Label>
. ReturnsNone
if the string does not conform to any known label syntax. - set_
ascent - Set the ascent value for a font based on its glyphs
- to_
yaff_ string