From 13a85df430f32750a1d31372f648e58b3f0c7c9f Mon Sep 17 00:00:00 2001 From: memdmp Date: Sun, 12 Jan 2025 02:57:36 +0100 Subject: feat: specify amount to advance x position --- build.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'build.rs') diff --git a/build.rs b/build.rs index ac7a5c4..bbabf0e 100644 --- a/build.rs +++ b/build.rs @@ -60,7 +60,7 @@ impl FontMetadata { } define_item( &mut image, - 10 + ((width as usize) * (height as usize)), + 14 + ((width as usize) * (height as usize)), 0x00, ); @@ -72,11 +72,12 @@ impl FontMetadata { // TODO: do we *really* need i32 values here? wouldn't i16 be sufficient? image[2..6].copy_from_slice(&pixel_bounding_box.min.x.to_le_bytes()); image[6..10].copy_from_slice(&(pixel_bounding_box.min.y + (scale.y / 2.0) as i32).to_le_bytes()); + image[10..14].copy_from_slice(&(glyph.h_metrics().advance_width).to_le_bytes()); positioned_glyph.draw(|gx: u32, gy: u32, v| { let bit = (v * 255.0) as u8; if gx < width { - define_item(&mut image, (10 + (gy * width) + gx) as usize, bit); + define_item(&mut image, (14 + (gy * width) + gx) as usize, bit); } }); image @@ -145,8 +146,12 @@ fn generate_struct(font: &FontMetadata) -> io::Result { let mut contents = format!( "pub struct {name}Struct {{}} impl BakedFont for {name}Struct {{ + fn font_scale_y() -> f32 {{ + {} + }} fn has_char(&self, c: char) -> bool {{ - match c as u8 {{" + match c as u8 {{", + format!("{}{}",font.scale.y.to_string(),if font.scale.y % 1.0 == 0.0 {".0"} else {""}) ); for char in font.unique_chars() { contents = format!( @@ -197,7 +202,7 @@ use crate::font::BakedFont; name: "Galmuri", font: { Font::try_from_vec(fs::read("assets/fonts/Galmuri11.ttf")?).unwrap() }, charset: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz2053: ", - scale: Scale::uniform(20.0), + scale: Scale::uniform(32.0), }, FontMetadata { name: "CherryBombOne", -- cgit v1.2.3