#font #console #read #optional #ones #automatic #was

psf

Allow to read psf fonts, including (optionally) zipped ones

2 unstable releases

0.2.0 Oct 20, 2020
0.1.0 Oct 17, 2020

#13 in #ones

32 downloads per month

MIT license

13KB
251 lines

psf

Reads psf (console) font files with optional support for automatic unzipping.

Decoding of the psf format was possible thanks to the nafe tool.

How to use

use psf::Font;

let the_font = Font::new("<path>");
if let Ok(font) = the_font {
    let c = font.get_char('X');
    if let Some(c) = c {
        println!("{:-<1$}", "", c.width() + 2);
        for h in 0..c.height() {
           print!("|");
           for w in 0..c.width() {
               let what = if c.get(w, h).unwrap() != 0 { "X" } else { " " };
               print!("{}", what);
           }
           println!("|");
       }
       println!("{:-<1$}", "", c.width() + 2);
    }
}

This is actually what method Font::print_char() is doing.


lib.rs:

Reads psf (console) fonts. Exposes very simple interface for displaying the glyphs.

Exposing of the glyph data is simple and easy to use:

use psf::Font;

let the_font = Font::new("<path>");
if let Ok(font) = the_font {
    let c = font.get_char('X');
    if let Some(c) = c {
        println!("{:-<1$}", "", c.width() + 2);
        for h in 0..c.height() {
           print!("|");
           for w in 0..c.width() {
               let what = if c.get(w, h).unwrap() { "X" } else { " " };
               print!("{}", what);
           }
           println!("|");
       }
       println!("{:-<1$}", "", c.width() + 2);
    }
}

Dependencies

~88KB