Coder Social home page Coder Social logo

unifont-rs's Introduction

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.

unifont-rs's People

Contributors

mkovaxx avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

konosh93

unifont-rs's Issues

bug: the example code is unaware of some Unicode details

For example, trying to make it render Arabic text yields the wrong result:

cargo run --example banner العربية

Output:

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.