From 41e9eda7909164724db0935a6b46566d4585135e Mon Sep 17 00:00:00 2001 From: anon Date: Sun, 2 Apr 2023 11:09:04 +0100 Subject: [PATCH] Simplified progressing through a UTF-8 string in ImageTextEx and MeasureTextEx. This change matches existing precedent in DrawTextEx --- src/rtext.c | 4 ++-- src/rtextures.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index 951844098..c988533d0 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1201,7 +1201,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing int letter = 0; // Current character int index = 0; // Index position in sprite font - for (int i = 0; i < size; i++) + for (int i = 0; i < size;) { byteCounter++; @@ -1209,7 +1209,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing letter = GetCodepointNext(&text[i], &next); index = GetGlyphIndex(font, letter); - i += next - 1; + i += next; if (letter != '\n') { diff --git a/src/rtextures.c b/src/rtextures.c index 2249b609f..bd652e6b3 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -1266,7 +1266,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co // Create image to store text imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK); - for (int i = 0; i < size; i++) + for (int i = 0; i < size;) { // Get next codepoint from byte string and glyph index in font int codepointByteCount = 0; @@ -1292,7 +1292,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co else textOffsetX += font.glyphs[index].advanceX + (int)spacing; } - i += (codepointByteCount - 1); // Move text bytes counter to next codepoint + i += codepointByteCount; // Move text bytes counter to next codepoint } // Scale image depending on text size