#font #unicode #monochrome #bitmap-font #bitmap

unifont

Provides a monochrome Unicode bitmap font. Halfwidth glyphs are 8x16, fullwidth are 16x16 pixels.

3 releases (stable)

new 1.1.0+data-15.1.05 Apr 24, 2024
1.0.0+data-15.1.05 Apr 1, 2024
0.1.0 Jun 1, 2018

#359 in Encoding

Download history 2/week @ 2024-02-15 10/week @ 2024-02-22 12/week @ 2024-02-29 5/week @ 2024-03-07 2/week @ 2024-03-14 150/week @ 2024-03-28 37/week @ 2024-04-04 1/week @ 2024-04-11

188 downloads per month
Used in ectoplasm

MIT license

1MB
276 lines

unifont-rs

Unifont for Rust

Provides a monochrome bitmap font that covers the entire Unicode Basic Multilingual Plane. Halfwidth glyphs are 8x16, fullwidth are 16x16 pixels.

Features

  • easy to use
  • access to raw binary data
  • #[no_std] for embedded use
  • small memory footprint
  • basic i18n support

API

fn get_glyph(c: char) -> Option<&'static Glyph>;
fn enumerate_glyphs() -> impl Iterator<Item = (char, &'static Glyph)>;

enum Glyph {
    Halfwidth([u8; 16]),
    Fullwidth([u16; 16]),
}

impl Glyph {
    fn get_pixel(&self, x: usize, y: usize) -> bool;
    fn get_width(&self) -> usize;
    fn is_fullwidth(&self) -> bool;
}

/// Preprocess text so that it may be rendered via Unifont.
pub fn preprocess_text(text: &str) -> String;

Example Code

Example code is under examples/banner.rs.

Run the binary with the following command:

cargo run --example banner UniFont

It will produce the following output:

                                                        
                                                        
                                                        
                    #                                   
 #    #             #    ######                    #    
 #    #                  #                         #    
 #    #  # ###     ##    #        ####   # ###     #    
 #    #  ##   #     #    #       #    #  ##   #  #####  
 #    #  #    #     #    #####   #    #  #    #    #    
 #    #  #    #     #    #       #    #  #    #    #    
 #    #  #    #     #    #       #    #  #    #    #    
 #    #  #    #     #    #       #    #  #    #    #    
 #    #  #    #     #    #       #    #  #    #    #    
  ####   #    #   #####  #        ####   #    #     ##  
                                                        
                                                        

i18n (Internationalization)

Basic preprocessing is provided for displaying text in non-Latin scripts, such as Arabic.

Try running the example as follows:

cargo run --example banner "أبجد"

It will produce the following output:

                           ##   
                          #     
                           ##   
                          #     
                            #   
                            #   
    #                       #   
     #              #       #   
      #   ###        #      #   
 #    #      ##      #      #   
 #####################      #   
                                
           #                    
                   #            
                                
                                

How it Works

At compile time, the build.rs script parses the data/unifont-*.hex file and emits Rust code.

No runtime deps