Parcourir la source

Added a font glyph for missing characters

Sam Lantinga il y a 9 mois
Parent
commit
0804598b5d
1 fichiers modifiés avec 19 ajouts et 4 suppressions
  1. 19 4
      src/test/SDL_test_font.c

+ 19 - 4
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;