From 528e164ac5e1a4ecca404c7f54e98325a55b959f Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 6 May 2019 10:17:34 +0200 Subject: [PATCH] Corrected issue with wrong text measuring --- src/text.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/text.c b/src/text.c index 15b8d555..1050d12d 100644 --- a/src/text.c +++ b/src/text.c @@ -833,8 +833,8 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color) void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) { int length = strlen(text); - int textOffsetX = 0; // Offset between characters int textOffsetY = 0; // Required for line break! + float textOffsetX = 0.0f; // Offset between characters float scaleFactor = 0.0f; int letter = 0; // Current character @@ -856,7 +856,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f { // NOTE: Fixed line spacing of 1.5 lines textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor); - textOffsetX = 0; + textOffsetX = 0.0f; } else { @@ -869,8 +869,8 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f font.chars[index].rec.height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, tint); } - if (font.chars[index].advanceX == 0) textOffsetX += (int)(font.chars[index].rec.width*scaleFactor + spacing); - else textOffsetX += (int)(font.chars[index].advanceX*scaleFactor + spacing); + if (font.chars[index].advanceX == 0) textOffsetX += ((float)font.chars[index].rec.width*scaleFactor + spacing); + else textOffsetX += ((float)font.chars[index].advanceX*scaleFactor + spacing); } } } @@ -1053,6 +1053,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing int next = 1; letter = GetNextCodepoint(&text[i], &next); + // NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) // but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set `next = 1` if(letter == 0x3f) next = 1;