LibYAFF: Yet Another Font Format Library
A Rust library for parsing, manipulating, and generating bitmap fonts in the YAFF format. YAFF is a human-readable, line-based format for describing bitmap fonts, supporting kerning and multiple labels for each glyph.
Includes a handy tool to convert vector fonts (TTF, OTF, and more) to YAFF format - see the Tools section below.
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.
Cargo Features
This crate has the following cargo features:
parsing(enabled by default): Enables the font parsing functionality. This feature depends on theregexcrate.encoding(enabled by default): Enables the font encoding functionality for generating YAFF format output.
Quick Start
Add libyaff to your Cargo.toml:
[]
= "0.1.0"
Load a YAFF font from a file and inspect its properties:
use ;
Tools
vector2yaff
The vector2yaff tool converts vector fonts (TTF, OTF, etc.) to YAFF format using FreeType.
# Build the tool
# Convert a font with specific character range
# With custom DPI
Arguments:
TTF_PATH: Path to the font file (TTF, OTF, etc.)POINT_SIZE: Desired point size for renderingRANGE: Character range(s) to include (e.g.,0x20-0x7Efor ASCII printable,32-126for decimal)OUTPUT_YAFF: Output YAFF file path
Options:
--dpi <DPI>: DPI for rendering (default: 72)
Supported formats:
- TrueType (.ttf, .ttc)
- OpenType (.otf, .otc)
- Type 1 (.pfa, .pfb)
- And many more via FreeType
Building and Testing
This project includes a test.sh script that can be used to build and test the library. The script uses the example code in examples/test.rs to parse a YAFF file and then write it back out.
To run the tests, execute the following command:
Arguments:
YAFF_FILES_DIR: Directory containing.yafffiles to test
What the test does: The test script performs a round-trip validation by:
- Parsing each
.yafffile in the specified directory - Writing it back out to a temporary file
- Parsing that temporary file and writing it out again
- Comparing the two temporary outputs to ensure they're identical
This validates that the library can parse and generate YAFF files consistently without data loss.
Example usage:
# Test with hoard-of-bitfonts repository
- If a file cannot be parsed, the script prints
ERRORwith details and continues. - If differences are detected, it will show a diff and exit with an error.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Author
Michael Steil mist64@mac.com