summaryrefslogtreecommitdiffhomepage
path: root/src/text.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2019-01-05 15:04:18 +0100
committerraysan5 <[email protected]>2019-01-05 15:04:18 +0100
commit1038e79b364d75a037e2b71e1a7dbc5937f88f1b (patch)
treef5c27c83602bacd47434ee04fc3d2c282e4d4639 /src/text.c
parent0bacc978c39a234da4a2b73ce3cb5b43e072a103 (diff)
downloadraylib-1038e79b364d75a037e2b71e1a7dbc5937f88f1b.tar.gz
raylib-1038e79b364d75a037e2b71e1a7dbc5937f88f1b.zip
Corrected issue with text measure on Latin-1 chars
Considering chars inputs come in UTF8 form!
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/text.c b/src/text.c
index 0b343af3..7b2b67bb 100644
--- a/src/text.c
+++ b/src/text.c
@@ -935,13 +935,30 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
float textHeight = (float)font.baseSize;
float scaleFactor = fontSize/(float)font.baseSize;
+ unsigned char letter = 0; // Current character
+ int index = 0; // Index position in sprite font
+
for (int i = 0; i < len; i++)
{
lenCounter++;
-
+
if (text[i] != '\n')
{
- int index = GetGlyphIndex(font, (int)text[i]);
+ if ((unsigned char)text[i] == 0xc2) // UTF-8 encoding identification
+ {
+ // Support UTF-8 encoded values from [0xc2 0x80] -> [0xc2 0xbf](¿)
+ letter = (unsigned char)text[i + 1];
+ index = GetGlyphIndex(font, (int)letter);
+ i++;
+ }
+ else if ((unsigned char)text[i] == 0xc3) // UTF-8 encoding identification
+ {
+ // Support UTF-8 encoded values from [0xc3 0x80](À) -> [0xc3 0xbf](ÿ)
+ letter = (unsigned char)text[i + 1];
+ index = GetGlyphIndex(font, (int)letter + 64);
+ i++;
+ }
+ else index = GetGlyphIndex(font, (unsigned char)text[i]);
if (font.chars[index].advanceX != 0) textWidth += font.chars[index].advanceX;
else textWidth += (font.chars[index].rec.width + font.chars[index].offsetX);