Skip to content

[Renderers/Raylib] Add support for multibyte UTF-8 characters in Raylib_MeasureText - #650

Open
hensing1 wants to merge 3 commits into
nicbarker:mainfrom
hensing1:main
Open

hensing1 wants to merge 3 commits into
nicbarker:mainfrom
hensing1:main

Conversation

@hensing1

Copy link
Copy Markdown

The present implementation for the text measuring function in the raylib renderer does not support multibyte UTF-8 codepoints, such as German umlauts.

Worse, since the leading bit of the first byte in a multibyte UTF-8 sequence is always a 1, the index calculated by int index = text.chars[i] - 32; is guaranteed to be negative, making fontToUse.glyphs[index].advanceX read into random memory.
Also, the order in which the glyphs are present in the glyphs field of a raylib font can be arbitrary, for example when loaded with custom code points using raylib's LoadFontEx().

This fix employs the functions GetCodepoint() and GetGlyphInfo(), both provided by raylib.

It also addresses the point raised in #634 .

@rats159

rats159 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

I did something similar for the Odin raylib renderer, and I recommend not making this the default, a lot of text is so ascii, and it's significantly faster to work with than full utf-8. In the Odin version I have measure_text_ascii and measure_text_utf8, with measure_text being an alias for the ascii one. I'd recommend a similar approach here to keep performance, while adding the more expensive option when necessary

@hensing1

Copy link
Copy Markdown
Author

@rats159 fair enough, I've added the old function again. Lmk if this is ok

@hensing1 hensing1 changed the title Add support for multibyte UTF-8 characters in Raylib_MeasureText [Renderers/Raylib] Add support for multibyte UTF-8 characters in Raylib_MeasureText Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants