#bdf #glyph #font

bdf2

BDF format handling

1 unstable release

0.7.1 Dec 8, 2024

#2 in #bdf

Download history 135/week @ 2024-12-06 9/week @ 2024-12-13 4/week @ 2025-01-31 3/week @ 2025-02-07 3/week @ 2025-02-14 9/week @ 2025-02-21 7/week @ 2025-02-28 26/week @ 2025-03-07 37/week @ 2025-03-14

79 downloads per month

WTFPL license

62KB
1.5K SLoC

bdf

Build & Test

BDF font handler

This crate allows you to read and write BDF fonts in Rust.

Example

This example will draw a given glyph in your terminal using the given font.

use std::char;
use std::env;
use std::process::exit;

let font = bdf::open(env::args().nth(1).expect("missing font file")).unwrap();
let codepoint = char::from_u32(
    env::args()
        .nth(2)
        .expect("missing codepoint")
        .parse()
        .unwrap(),
)
.expect("invalid codepoint");
let glyph = font.glyphs().get(&codepoint).unwrap_or_else(|| exit(1));

for y in 0..glyph.height() {
    for x in 0..glyph.width() {
        if glyph.get(x, y) {
            print!("██");
        } else {
            print!("  ");
        }
    }
    print!("\n");
}

lib.rs:

BDF font handler

This crate allows you to read and write BDF fonts in Rust.

Example

This example will draw a given glyph in your terminal using the given font.

use std::char;
use std::env;
use std::process::exit;

let font = bdf::open(env::args().nth(1).expect("missing font file")).unwrap();
let codepoint = char::from_u32(
    env::args()
        .nth(2)
        .expect("missing codepoint")
        .parse()
        .unwrap(),
)
.expect("invalid codepoint");
let glyph = font.glyphs().get(&codepoint).unwrap_or_else(|| exit(1));

for y in 0..glyph.height() {
    for x in 0..glyph.width() {
        if glyph.get(x, y) {
            print!("██");
        } else {
            print!("  ");
        }
    }
    print!("\n");
}

Dependencies

~0.4–0.8MB
~19K SLoC