SDL_ttf: Fixed strings always wrapping if they contain ligatures

From b35c03d5e80b3e99dcbdee34269cdb21896e3e2d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 26 May 2022 23:06:07 -0700
Subject: [PATCH] Fixed strings always wrapping if they contain ligatures

Fixes https://github.com/libsdl-org/SDL_ttf/issues/225
---
 SDL_ttf.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/SDL_ttf.c b/SDL_ttf.c
index a33f074..650b99b 100644
--- a/SDL_ttf.c
+++ b/SDL_ttf.c
@@ -3354,7 +3354,21 @@ static int TTF_Size_Internal(TTF_Font *font,
             *extent = current_width;
         }
         if (count) {
-            *count = char_count;
+#if TTF_USE_HARFBUZZ
+            if (char_count == glyph_count) {
+                /* The higher level code doesn't know about ligatures,
+                 * so if we've covered all the glyphs, report the full
+                 * string length.
+                 *
+                 * If we have to line wrap somewhere in the middle, we
+                 * might be off by the number of ligatures, but there
+                 * isn't an easy way around that without using hb_buffer
+                 * at that level instead.
+                 */
+                *count = SDL_utf8strlen(text);
+            } else
+#endif
+                *count = char_count;
         }
     }