From 53f0901ceba6b264269171172232b44666e765f6 Mon Sep 17 00:00:00 2001 From: Corwin Date: Wed, 12 Jun 2024 17:29:39 +0100 Subject: [PATCH 1/2] fix the overflow bug on kerning / xmin on a new sprite --- agb/src/display/object/font/preprocess.rs | 8 ++++++-- agb/src/display/object/font/renderer.rs | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/agb/src/display/object/font/preprocess.rs b/agb/src/display/object/font/preprocess.rs index e07356a2..71435074 100644 --- a/agb/src/display/object/font/preprocess.rs +++ b/agb/src/display/object/font/preprocess.rs @@ -86,8 +86,12 @@ impl Preprocessor { ); self.width_in_sprite = 0; } - if self.width_in_sprite != 0 { - self.width_in_sprite += letter.xmin as i32; + self.width_in_sprite += letter.xmin as i32; + if self.width_in_sprite < 0 { + if let Some(back) = widths.back_mut() { + back.0 -= (-self.width_in_sprite).try_into().unwrap_or(0); + } + self.width_in_sprite = 0; } self.width_in_sprite += letter.advance_width as i32; } diff --git a/agb/src/display/object/font/renderer.rs b/agb/src/display/object/font/renderer.rs index bbd0628b..ac1f8f77 100644 --- a/agb/src/display/object/font/renderer.rs +++ b/agb/src/display/object/font/renderer.rs @@ -99,9 +99,8 @@ impl WordRender { None }; - if self.working.x_offset != 0 { - self.working.x_offset += font_letter.xmin as i32; - } + self.working.x_offset += font_letter.xmin as i32; + self.working.x_offset = self.working.x_offset.max(0); let y_position = font.ascent() - font_letter.height as i32 - font_letter.ymin as i32; From cbf0fa0a23c1b01acbe4fc747667732d550bec5a Mon Sep 17 00:00:00 2001 From: Corwin Date: Wed, 12 Jun 2024 17:33:46 +0100 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36bd4098..95ff89e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Affine background center position didn't work outside of the upper left quadrant of the gba's screen. - Fixed backtrace pointing to the wrong line of code (being out by one). +- Fixes overflow caused by certain font characteristics on boundaries of sprites in the object text renderer. ## [0.20.2] - 2024/05/25