Crate libyaff

Crate libyaff 

Source
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.
GlyphDefinition
A single glyph definition including bitmap data and typography metrics.
YaffFont

Enums§

FontSpacing
Label
Glyph labeling system supporting Unicode, legacy codepoints, and custom tags.
LineType
ParseError
WritingDirection

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>. Returns None 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