Crate font8x8 [] [src]

8x8 monochrome bitmap fonts for rendering

This crate contains a Rust implementation of a public domain 8-bit by 8-bit font.

Usage

To use this crate, add to your Cargo.toml:

[dependencies]
font8x8 = "0.1"

Then, in your code:

extern crate font8x8;

use font8x8;

Example

Working directly with legacy constants

Let's say we want to print out the first character belonging to the greek subset. In this case, it corresponds to the unicode U+0390 described as iota with tonos and diaeresis, and we will retrieve it from the GREEK_LEGACY constant provided by our library.

Specifically, we will be working with GREEK_LEGACY[0], which is an array of bytes with capacity for eight separate bytes ([u8; 8]).

Here's a program that will print the character to your terminal, by parsing each byte of the array, inspecting it bit by bit, and printing an empty space " " for 0, and "█" for 1.

extern crate font8x8;

use font8x8::legacy::GREEK_LEGACY;

fn main() {
    for x in &GREEK_LEGACY[0] {
        for bit in 0..8 {
            match *x & 1 << bit {
                0 => print!(" "),
                _ => print!("█"),
            }
        }
        println!()
    }
}

The generated output should mostly resemble this (it will depend on your terminal's font settings):

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

and, it's meant to look like this: ΐ.

Working with fonts as UTF16

We can also use UTF16-encoded text to render the font on stdout.

This time, instead of using the index of the GREEK_LEGACY constant, we can use the trait method Utf16Fonts::get to retrieve the font rendering using the u16 as key.

extern crate font8x8;

use font8x8::{GREEK_FONTS, Utf16Fonts};

fn main() {
    if let Some(font_render) = GREEK_FONTS.get('ΐ' as u16) {
        for x in &font_render {
            for bit in 0..8 {
                match *x & 1 << bit {
                    0 => print!(" "),
                    _ => print!("█"),
                }
            }
            println!()
        }
    }
}

On the miscellanous characters included

These characters are provided as-is, and some don't have a proper unicode point. They are provided in the MISC and SGA contants. For a description, please read the constant documentation.

Credits

Initially extracted from an asm file, fetched from a now broken link: http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm

It was then ported to a C header file, also in the Public Domain, https://github.com/dhepper/font8x8.

This crate is an extension of that work.

Re-exports

pub use self::utf16::FontUtf16;
pub use self::utf16::Utf16Fonts;

Modules

legacy

Re-export the original [u8; 8] constants, taken from C-header files. Legacy constants.

utf16

utf16 support for fonts.

Structs

FromUtf16Error

A possible error value when converting a String from a UTF-16 byte slice.

Constants

BASIC_FONTS

A convenient constant for Basic Latin fonts (U+0000 - U+007F), that implements the Utf16Fonts trait.

BLOCK_FONTS

A convenient constant for Block Element fonts (U+2580 - U+259F), that implements the Utf16Fonts trait.

BOX_FONTS

A convenient constant for Box Element fonts (U+2500 - U+257F), that implements the Utf16Fonts trait.

GREEK_FONTS

A convenient constant for Greek fonts (U+0390 - U+03C9), that implements the Utf16Fonts trait.

HIRAGANA_FONTS

A convenient constant for Hiragana fonts (U+3040 - U+309F), that implements the Utf16Fonts trait.

LATIN_FONTS

A convenient constant for Extended Latin fonts (U+00A0 - U+00FF), that implements the Utf16Fonts trait.

MISC_FONTS

A convenient constant for Miscellanous fonts (U+20A7, U+0192, U+00AA, U+00BA, U+2310, U+2264, U+2265, U+0060, U+1EF2, and U+1EF3), that implements the Utf16Fonts trait.

SGA_FONTS

A convenient constant for special SGA fonts (U+E541 - U+E55A), that implements the Utf16Fonts trait.