bitfont 0.1.0

Takes an ASCII string and generates a vector containing a bitmap font, for easy overlay into images.
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 10.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.15 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • david-griffith/rust-bitmap
    8 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • david-griffith

rust-bitmap

A very simple bitmap font generator for rust.

Contains a simple 8x8 bitmap font containing ASCII character codes from 0x20 - 7F (Space, 0-9, A-Z, a-z, punctuation) If the string contains characters outside the 0x20 - 0x7F ASCII range, an error is returned.

It contains a few functions that you feed a string, and you'll get a Result in return that has a vector of 8 vectors, with each vector containing the value for a single row of the generated bitmap font. This can then be easily looped through in your program to plug pixels into whatever imaging library you're using, or print to the console as in the example below.

Functions currently implemented are:

  • A luma function that takes foreground/background brightness values and returns a vector of those, useful for greyscale.
  • A boolean function that simply returns a vector of true/false values that you can do what you want with.

Example code:

   extern crate bitfont;
   
   fn main() {
       use bitfont::bitmap_luma;
       let my_vec = bitmap_luma("abc123456", 8, 0).unwrap();
       for my_row in my_vec {
           for my_char in my_row {
               if my_char > 0 {
                   print!("");
               } else {
                   print!(" ");
               }
           }
           println!();
       }
       
       use bitfont::bitmap_bool;
       let my_vec = bitmap_bool("abc123456").unwrap();
       for my_row in my_vec {
           for my_char in my_row {
               if *my_char {
                   print!("");
               } else {
                   print!(" ");
               }
           }
           println!();
       }
   }

Running the example code above should generate the following from the luma and bool functions:

        ███               ██     ████    ████      ███  ██████    ███   
         ██              ███    ██  ██  ██  ██    ████  ██       ██     
 ████    ██      ████     ██        ██      ██   ██ ██  █████   ██      
    ██   █████  ██  ██    ██      ███     ███   ██  ██      ██  █████   
 █████   ██  ██ ██        ██     ██         ██  ███████     ██  ██  ██  
██  ██   ██  ██ ██  ██    ██    ██  ██  ██  ██      ██  ██  ██  ██  ██  
 ███ ██ ██ ███   ████   ██████  ██████   ████      ████  ████    ████   
                                                                        
        ███               ██     ████    ████      ███  ██████    ███   
         ██              ███    ██  ██  ██  ██    ████  ██       ██     
 ████    ██      ████     ██        ██      ██   ██ ██  █████   ██      
    ██   █████  ██  ██    ██      ███     ███   ██  ██      ██  █████   
 █████   ██  ██ ██        ██     ██         ██  ███████     ██  ██  ██  
██  ██   ██  ██ ██  ██    ██    ██  ██  ██  ██      ██  ██  ██  ██  ██  
 ███ ██ ██ ███   ████   ██████  ██████   ████      ████  ████    ████