Added a font glyph for missing characters

This commit is contained in:
Sam Lantinga 2024-06-24 19:53:04 -07:00
parent def7a43a2e
commit 0804598b5d

View File

@ -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;