SDL: Added a font glyph for missing characters

From 0804598b5d2919c733c24f8cc471461d5a33f75f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 24 Jun 2024 19:53:04 -0700
Subject: [PATCH] Added a font glyph for missing characters

---
 src/test/SDL_test_font.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/test/SDL_test_font.c b/src/test/SDL_test_font.c
index 67e2c17ba9603..3c246d3a5b3e3 100644
--- a/src/test/SDL_test_font.c
+++ b/src/test/SDL_test_font.c
@@ -35,6 +35,8 @@
 ;
 */
 
+#define NUM_FONT_GLYPHS 257
+
 static unsigned char SDLTest_FontData[] = {
 
     /*
@@ -3110,14 +3112,26 @@ static unsigned char SDLTest_FontData[] = {
     0x30, /* 00001100 */
     0x1f, /* 11111000 */
 
+    /*
+     * 256 0x100 - missing character
+     */
+    0x55, /* 01010101 */
+    0xAA, /* 10101010 */
+    0x55, /* 01010101 */
+    0xAA, /* 10101010 */
+    0x55, /* 01010101 */
+    0xAA, /* 10101010 */
+    0x55, /* 01010101 */
+    0xAA, /* 10101010 */
 };
+SDL_COMPILE_TIME_ASSERT(SDLTest_FontDataSize, SDL_arraysize(SDLTest_FontData) == NUM_FONT_GLYPHS * 8);
 
 /* ---- Character */
 
 struct SDLTest_CharTextureCache
 {
     SDL_Renderer *renderer;
-    SDL_Texture *charTextureCache[256];
+    SDL_Texture *charTextureCache[NUM_FONT_GLYPHS];
     struct SDLTest_CharTextureCache *next;
 };
 
@@ -3163,6 +3177,9 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
 
     /* Character index in cache */
     ci = c;
+    if (ci >= NUM_FONT_GLYPHS) {
+        ci = (NUM_FONT_GLYPHS - 1);
+    }
 
     /* Search for this renderer's cache */
     for (cache = SDLTest_CharTextureCacheList; cache; cache = cache->next) {
@@ -3342,9 +3359,7 @@ int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s)
     while (len > 0 && !result) {
         int advance = 0;
         Uint32 ch = UTF8_getch(s, len, &advance);
-        if (ch < 256) {
-            result |= SDLTest_DrawCharacter(renderer, curx, cury, ch);
-        }
+        result |= SDLTest_DrawCharacter(renderer, curx, cury, ch);
         curx += charWidth;
         s += advance;
         len -= advance;