summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-04-06 12:49:59 +0200
committerRay <[email protected]>2023-04-06 12:49:59 +0200
commitd8c7b01a3cef6ebf3f5ea7db3974c1de2316171d (patch)
tree30e9f8088d3498d725e58e6ea7a72a21fb616bd1 /src
parent8367abad1a925fc7cf60fd8e71b5f6dbf6250ddb (diff)
downloadraylib-d8c7b01a3cef6ebf3f5ea7db3974c1de2316171d.tar.gz
raylib-d8c7b01a3cef6ebf3f5ea7db3974c1de2316171d.zip
REVIEWED: `GetGlyphIndex()` #3000
Diffstat (limited to 'src')
-rw-r--r--src/rtext.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/rtext.c b/src/rtext.c
index dda99487..1d2b4f35 100644
--- a/src/rtext.c
+++ b/src/rtext.c
@@ -1239,17 +1239,17 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
// NOTE: If codepoint is not found in the font it fallbacks to '?'
int GetGlyphIndex(Font font, int codepoint)
{
-#ifndef GLYPH_NOTFOUND_CHAR_FALLBACK
- #define GLYPH_NOTFOUND_CHAR_FALLBACK 63 // Character used if requested codepoint is not found: '?'
-#endif
-
-// Support charsets with any characters order
+ int index = 0;
+
#define SUPPORT_UNORDERED_CHARSET
#if defined(SUPPORT_UNORDERED_CHARSET)
- int index = GLYPH_NOTFOUND_CHAR_FALLBACK;
+ int fallbackIndex = 0; // Get index of fallback glyph '?'
+ // Look for character index in the unordered charset
for (int i = 0; i < font.glyphCount; i++)
{
+ if (font.glyphs[i].value == 63) fallbackIndex = i;
+
if (font.glyphs[i].value == codepoint)
{
index = i;
@@ -1257,10 +1257,12 @@ int GetGlyphIndex(Font font, int codepoint)
}
}
- return index;
+ if ((index == 0) && (font.glyphs[0].value != codepoint)) index = fallbackIndex;
#else
- return (codepoint - 32);
+ index = codepoint - 32;
#endif
+
+ return index;
}
// Get glyph font info data for a codepoint (unicode character)