From f87f0f26b21d445877658d7725472c666c2ee40c Mon Sep 17 00:00:00 2001 From: memdmp Date: Sat, 11 Jan 2025 23:55:01 +0100 Subject: feat: calculate height based on width --- src/font.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/font.rs b/src/font.rs index d4e8d88..7df0545 100644 --- a/src/font.rs +++ b/src/font.rs @@ -16,7 +16,11 @@ fn insert_value(arr: &mut Vec<*const Glyph>, idx: usize, glyph: *const Glyph) { } pub struct RenderableCharacter { + /** The width of the character, indicating where to break into a newline */ pub width: u16, + /** The height of the character, derived from data's length divided by width */ + pub height: u16, + /** The raw alpha layer of the character */ pub data: &'static [u8], } /** @@ -26,9 +30,12 @@ pub trait BakedFont { fn get_char_bytes(character: char) -> &'static [u8]; fn get_char(character: char) -> RenderableCharacter { let bytes = Self::get_char_bytes(character); + let width = (bytes[0] as u16) | (bytes[1] as u16 >> 8); + let data = &bytes[2..]; RenderableCharacter { - width: (bytes[0] as u16) | (bytes[1] as u16 >> 8) , - data: &bytes[2..] + width, + height: data.len() as u16 / width, + data, } } } -- cgit v1.2.3