account for variable width spacing
This commit is contained in:
@@ -32,6 +32,8 @@ impl Font {
|
||||
}
|
||||
|
||||
pub fn get_char_bitmap(&self, index: u64) -> Option<Vec<Vec<u8>>> {
|
||||
let mut char_width: u8 = 0;
|
||||
|
||||
let bytes = self
|
||||
.font_parsed
|
||||
.get("data")?
|
||||
@@ -39,6 +41,8 @@ impl Font {
|
||||
.iter()
|
||||
.find(|entry| entry.get("n").map_or(false, |n| n == index))
|
||||
.and_then(|character| {
|
||||
char_width = character.get("w")?.as_u64().unwrap() as u8;
|
||||
|
||||
character.get("b")?.as_array().map(|arr| {
|
||||
arr.iter()
|
||||
.filter_map(|val| val.as_u64())
|
||||
@@ -52,7 +56,10 @@ impl Font {
|
||||
.flat_map(|&byte| (0..8).rev().map(move |i| (byte >> i) & 1))
|
||||
.collect::<Vec<u8>>();
|
||||
|
||||
let char_matrix = bits.chunks(5).map(|chunk| chunk.to_vec()).collect();
|
||||
let char_matrix = bits
|
||||
.chunks(char_width.into())
|
||||
.map(|chunk| chunk.to_vec())
|
||||
.collect();
|
||||
|
||||
Some(char_matrix)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ fn build_ui(app: >k::Application) {
|
||||
// insert_matrix_at(&mut dot_matrix, &insert_matrix, 0, 6);
|
||||
// insert_matrix_at(&mut dot_matrix, &char_bitmap, 0, 12);
|
||||
|
||||
let thing = String::from("i");
|
||||
let thing = String::from("ABCDEFG");
|
||||
let ascii_values: &Vec<u8> = &thing.chars().map(|c| c as u8).collect();
|
||||
|
||||
let mut col_offset = 0;
|
||||
|
||||
Reference in New Issue
Block a user