From ed02fbd36916d3a7d5f763f0b17a6c0070385129 Mon Sep 17 00:00:00 2001 From: anon Date: Sun, 2 Apr 2023 11:00:35 +0100 Subject: [PATCH] Change default behaviour of GetCodepointNext to return a size of 1 instead of 0. This matches existing prod behaviour and guarantees size 1..4 is returned. Simplify internal code that uses GetCodepointNext that previously had to account for size=0. --- src/rtext.c | 16 +++------------- src/rtextures.c | 4 ---- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index 32379551a..951844098 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1071,10 +1071,6 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f int codepoint = GetCodepointNext(&text[i], &codepointByteCount); int index = GetGlyphIndex(font, codepoint); - // NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all the bad bytes using the '?' symbol moving one byte - if (codepoint == 0x3f) codepointByteCount = 1; - if (codepoint == '\n') { // NOTE: Fixed line spacing of 1.5 line-height @@ -1213,9 +1209,6 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing letter = GetCodepointNext(&text[i], &next); index = GetGlyphIndex(font, letter); - // NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all the bad bytes using the '?' symbol so to not skip any we set next = 1 - if (letter == 0x3f) next = 1; i += next - 1; if (letter != '\n') @@ -1704,9 +1697,7 @@ int *LoadCodepoints(const char *text, int *count) for (int i = 0; i < textLength; codepointCount++) { codepoints[codepointCount] = GetCodepointNext(text + i, &codepointSize); - - if (codepoints[codepointCount] == 0x3f) i += 1; - else i += codepointSize; + i += codepointSize; } // Re-allocate buffer to the actual number of codepoints loaded @@ -1736,8 +1727,7 @@ int GetCodepointCount(const char *text) int next = 0; int letter = GetCodepointNext(ptr, &next); - if (letter == 0x3f) ptr += 1; - else ptr += next; + ptr += next; length++; } @@ -1898,7 +1888,7 @@ int GetCodepointNext(const char *text, int *codepointSize) { const char *ptr = text; int codepoint = 0x3f; // Codepoint (defaults to '?') - *codepointSize = 0; + *codepointSize = 1; // Get current codepoint and bytes processed if (0xf0 == (0xf8 & ptr[0])) diff --git a/src/rtextures.c b/src/rtextures.c index fb63f2ff0..2249b609f 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -1273,10 +1273,6 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co int codepoint = GetCodepointNext(&text[i], &codepointByteCount); // WARNING: Module required: rtext int index = GetGlyphIndex(font, codepoint); // WARNING: Module required: rtext - // NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all the bad bytes using the '?' symbol moving one byte - if (codepoint == 0x3f) codepointByteCount = 1; - if (codepoint == '\n') { // NOTE: Fixed line spacing of 1.5 line-height