SDL_ttf: Fixed bug #299 - Bitmap font spacing incorrect when using Harfbuzz

From ed71a1555b5f5f618ba7a37554592c1f688ca275 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Tue, 1 Aug 2023 22:42:35 +0200
Subject: [PATCH] Fixed bug #299 - Bitmap font spacing incorrect when using
 Harfbuzz

---
 src/SDL_ttf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index 8803181..190ee96 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -3153,6 +3153,7 @@ static int TTF_Size_Internal(TTF_Font *font,
     hb_glyph_info_t *hb_glyph_info;
     hb_glyph_position_t *hb_glyph_position;
     int y = 0;
+    int advance_if_bold = 0;
 #else
     size_t textlen;
     int skip_first = 1;
@@ -3195,6 +3196,12 @@ static int TTF_Size_Internal(TTF_Font *font,
     font->pos_len = 0;
 
 #if TTF_USE_HARFBUZZ
+
+    /* Adjust for bold text */
+    if (TTF_HANDLE_STYLE_BOLD(font)) {
+        advance_if_bold = F26Dot6(font->glyph_overhang);
+    }
+
     /* Create a buffer for harfbuzz to use */
     hb_buffer = hb_buffer_create();
     if (hb_buffer == NULL) {
@@ -3269,7 +3276,7 @@ static int TTF_Size_Internal(TTF_Font *font,
         /* Compute positions */
         pos_x  = x                     + x_offset;
         pos_y  = y + F26Dot6(font->ascent) - y_offset;
-        x     += x_advance;
+        x     += x_advance + advance_if_bold;
         y     += y_advance;
 #else
         /* Compute positions */