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.

This commit is contained in:
anon 2023-04-02 11:00:35 +01:00
parent fb89eac7dc
commit ed02fbd369
2 changed files with 3 additions and 17 deletions

View File

@ -1071,10 +1071,6 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
int codepoint = GetCodepointNext(&text[i], &codepointByteCount); int codepoint = GetCodepointNext(&text[i], &codepointByteCount);
int index = GetGlyphIndex(font, codepoint); 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') if (codepoint == '\n')
{ {
// NOTE: Fixed line spacing of 1.5 line-height // 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); letter = GetCodepointNext(&text[i], &next);
index = GetGlyphIndex(font, letter); 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; i += next - 1;
if (letter != '\n') if (letter != '\n')
@ -1704,9 +1697,7 @@ int *LoadCodepoints(const char *text, int *count)
for (int i = 0; i < textLength; codepointCount++) for (int i = 0; i < textLength; codepointCount++)
{ {
codepoints[codepointCount] = GetCodepointNext(text + i, &codepointSize); codepoints[codepointCount] = GetCodepointNext(text + i, &codepointSize);
i += codepointSize;
if (codepoints[codepointCount] == 0x3f) i += 1;
else i += codepointSize;
} }
// Re-allocate buffer to the actual number of codepoints loaded // Re-allocate buffer to the actual number of codepoints loaded
@ -1736,8 +1727,7 @@ int GetCodepointCount(const char *text)
int next = 0; int next = 0;
int letter = GetCodepointNext(ptr, &next); int letter = GetCodepointNext(ptr, &next);
if (letter == 0x3f) ptr += 1; ptr += next;
else ptr += next;
length++; length++;
} }
@ -1898,7 +1888,7 @@ int GetCodepointNext(const char *text, int *codepointSize)
{ {
const char *ptr = text; const char *ptr = text;
int codepoint = 0x3f; // Codepoint (defaults to '?') int codepoint = 0x3f; // Codepoint (defaults to '?')
*codepointSize = 0; *codepointSize = 1;
// Get current codepoint and bytes processed // Get current codepoint and bytes processed
if (0xf0 == (0xf8 & ptr[0])) if (0xf0 == (0xf8 & ptr[0]))

View File

@ -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 codepoint = GetCodepointNext(&text[i], &codepointByteCount); // WARNING: Module required: rtext
int index = GetGlyphIndex(font, codepoint); // 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') if (codepoint == '\n')
{ {
// NOTE: Fixed line spacing of 1.5 line-height // NOTE: Fixed line spacing of 1.5 line-height