SDL_ttf: - Un-activate SDF if we're trying to render in non blended mode. (7862c)

From 7862ccef54ed3b002a0bf05356bf0ab162f77a55 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Wed, 11 Jan 2023 11:13:42 +0100
Subject: [PATCH] - Un-activate SDF if we're trying to render in non blended
 mode. - Fix underline style trying to write out of bounds in SDF mode

---
 SDL_ttf.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/SDL_ttf.c b/SDL_ttf.c
index 16428b1..1220845 100644
--- a/SDL_ttf.c
+++ b/SDL_ttf.c
@@ -1025,6 +1025,12 @@ static void Draw_Line(TTF_Font *font, const SDL_Surface *textbuf, int column, in
     if (tmp > 0) {
         line_thickness -= tmp;
     }
+    /* Previous case also happens with SDF (render_sdf) , because 'spread' property
+     * requires to increase 'ystart'
+     * Check for valid value anyway.  */
+    if (line_thickness <= 0) {
+        return;
+    }
 
     /* Wrapped mode with an unbroken line: 'line_width' is greater that 'textbuf->w' */
     line_width = SDL_min(line_width, textbuf->w);
@@ -3474,6 +3480,16 @@ static SDL_Surface* TTF_Render_Internal(TTF_Font *font, const char *text, const
         text = (const char *)utf8_alloc;
     }
 
+#if TTF_USE_SDF
+    /* Invalid cache if we were using SDF */
+    if (render_mode != RENDER_BLENDED) {
+        if (font->render_sdf) {
+            font->render_sdf = 0;
+            Flush_Cache(font);
+        }
+    }
+#endif
+
     /* Get the dimensions of the text surface */
     if ((TTF_Size_Internal(font, text, STR_UTF8, &width, &height, &xstart, &ystart, NO_MEASUREMENT) < 0) || !width) {
         TTF_SetError("Text has zero width");
@@ -3707,6 +3723,16 @@ static SDL_Surface* TTF_Render_Wrapped_Internal(TTF_Font *font, const char *text
         text_cpy = (char *)utf8_alloc;
     }
 
+#if TTF_USE_SDF
+    /* Invalid cache if we were using SDF */
+    if (render_mode != RENDER_BLENDED) {
+        if (font->render_sdf) {
+            font->render_sdf = 0;
+            Flush_Cache(font);
+        }
+    }
+#endif
+
     /* Get the dimensions of the text surface */
     if ((TTF_SizeUTF8(font, text_cpy, &width, &height) < 0) || !width) {
         TTF_SetError("Text has zero width");