Crates.io | unifont |
lib.rs | unifont |
version | 1.1.0+data-15.1.05 |
source | src |
created_at | 2018-06-01 06:10:56.794034 |
updated_at | 2024-04-24 13:59:01.737293 |
description | Provides a monochrome Unicode bitmap font. Halfwidth glyphs are 8x16, fullwidth are 16x16 pixels. |
homepage | https://github.com/mkovaxx/unifont-rs |
repository | https://github.com/mkovaxx/unifont-rs |
max_upload_size | |
id | 68028 |
size | 3,793,705 |
Unifont for Rust
Provides a monochrome bitmap font that covers the entire Unicode Basic Multilingual Plane. Halfwidth glyphs are 8x16, fullwidth are 16x16 pixels.
#[no_std]
for embedded usefn 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 is under examples/banner.rs
.
Run the binary with the following command:
cargo run --example banner UniFont
It will produce the following output:
#
# # # ###### #
# # # #
# # # ### ## # #### # ### #
# # ## # # # # # ## # #####
# # # # # ##### # # # # #
# # # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # # # #
#### # # ##### # #### # # ##
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:
##
#
##
#
#
#
# #
# # #
# ### # #
# # ## # #
##################### #
#
#
At compile time, the build.rs
script parses the data/unifont-*.hex
file and emits Rust code.