fix the overflow bug on kerning / xmin on a new sprite

This commit is contained in:
Corwin 2024-06-12 17:29:39 +01:00
parent 9ef4a8efcc
commit 53f0901ceb
No known key found for this signature in database
2 changed files with 8 additions and 5 deletions

View file

@ -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;
}

View file

@ -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;