| Crates.io | libyaff |
| lib.rs | libyaff |
| version | 0.1.1 |
| created_at | 2025-09-25 17:00:02.596304+00 |
| updated_at | 2025-09-25 17:06:31.871212+00 |
| description | Yet Another Font Format (YAFF) - A compact bitmap font format with kerning support |
| homepage | https://github.com/mist64/libyaff |
| repository | https://github.com/mist64/libyaff |
| max_upload_size | |
| id | 1854882 |
| size | 122,961 |
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.
This crate has the following cargo features:
parsing (enabled by default): Enables the font parsing functionality. This feature depends on the regex crate.encoding (enabled by default): Enables the font encoding functionality for generating YAFF format output.Add libyaff to your Cargo.toml:
[dependencies]
libyaff = "0.1.0"
Load a YAFF font from a file and inspect its properties:
use libyaff::{YaffFont, to_yaff_string};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a YAFF font from file
let font = YaffFont::from_path("my_font.yaff")?;
println!("Loaded font: {}", font.name.unwrap_or_default());
// 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)?;
Ok(())
}
The vector2yaff tool converts vector fonts (TTF, OTF, etc.) to YAFF format using FreeType.
# Build the tool
cargo build -p vector2yaff
# Convert a font with specific character range
cargo run -p vector2yaff -- font.ttf 12 0x20-0x7E output.yaff
# With custom DPI
cargo run -p vector2yaff -- --dpi 96 font.ttf 12 0x20-0x7E,0x20AC output.yaff
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-0x7E for ASCII printable, 32-126 for decimal)OUTPUT_YAFF: Output YAFF file pathOptions:
--dpi <DPI>: DPI for rendering (default: 72)Supported formats:
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:
./test.sh <YAFF_FILES_DIR>
Arguments:
YAFF_FILES_DIR: Directory containing .yaff files to testWhat the test does: The test script performs a round-trip validation by:
.yaff file in the specified directoryThis validates that the library can parse and generate YAFF files consistently without data loss.
Example usage:
# Test with hoard-of-bitfonts repository
git clone https://github.com/robhagemans/hoard-of-bitfonts
./test.sh hoard-of-bitfonts/hellschreiber
./test.sh hoard-of-bitfonts/atari/8-bit
ERROR with details and continues.This project is licensed under either of
at your option.
Michael Steil mist64@mac.com