aboutsummaryrefslogtreecommitdiffstats
path: root/src/font.rs
diff options
context:
space:
mode:
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,