aboutsummaryrefslogtreecommitdiffstats
path: root/src/font.rs
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpmemewarenet>2025-01-12 02:57:36 +0100
committerLibravatarLarge Libravatar memdmp <memdmpmemewarenet>2025-01-12 02:57:36 +0100
commit13a85df430f32750a1d31372f648e58b3f0c7c9f (patch)
tree465a96f1e3b9e7546dc19ea7422b77f81ac8c738 /src/font.rs
parent80528916dac1fe71bddc806fcf0fbd5434a73072 (diff)
downloadcosin25-invite-mountainbytes-13a85df430f32750a1d31372f648e58b3f0c7c9f.tar.gz
cosin25-invite-mountainbytes-13a85df430f32750a1d31372f648e58b3f0c7c9f.tar.bz2
cosin25-invite-mountainbytes-13a85df430f32750a1d31372f648e58b3f0c7c9f.tar.lz
cosin25-invite-mountainbytes-13a85df430f32750a1d31372f648e58b3f0c7c9f.zip

feat: specify amount to advance x position

Diffstat (limited to 'src/font.rs')
-rw-r--r--src/font.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/font.rs b/src/font.rs
index fc5217e..a547928 100644
--- a/src/font.rs
+++ b/src/font.rs
@@ -17,12 +17,15 @@ pub struct RenderableCharacter {
pub data: &'static [u8],
/** The offset to draw the character at */
pub offset: Point,
+ /** The amount to advance the x position of the cursor when drawing */
+ pub advance_width: f32,
}
/**
A trait describing a generated font.
We use traits implemented by each font because it's somehow optimized better in preliminary testing(?)
*/
pub trait BakedFont {
+ fn font_scale_y() -> f32;
fn has_char(&self, character: char) -> bool;
fn get_char_bytes(&self, character: char) -> &'static [u8];
fn get_char(&self, character: char) -> RenderableCharacter {
@@ -30,7 +33,8 @@ pub trait BakedFont {
let width = u16::from_le_bytes(bytes[0..2].try_into().unwrap());
let offset_x = i32::from_le_bytes(bytes[2..6].try_into().unwrap());
let offset_y = i32::from_le_bytes(bytes[6..10].try_into().unwrap());
- let data = &bytes[10..];
+ let advance_width = f32::from_le_bytes(bytes[10..14].try_into().unwrap());
+ let data = &bytes[14..];
let height = if data.len() == 0 {
0
} else {
@@ -41,6 +45,7 @@ pub trait BakedFont {
height,
offset: Point::new(offset_x, offset_y),
data,
+ advance_width,
}
}
}
@@ -93,7 +98,6 @@ impl RenderableCharacter {
surface.as_texture(texture_creator)
}
pub fn to_rect(&self, x: i32, y: i32) -> Rect {
- println!("{:#?}",self.offset);
Rect::new(
x + self.offset.x,
y + self.offset.y,