[rtext] New pair of functions to automatically prefetch all possible codepoints of any font (except empty ones) #4632
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @raysan5. Thanks for the cool set of libs! And this is my first PR ever, so I apologize if I'm forming something wrong.
I've tried all the appropriate functions to load fonts, but I still haven't found how to load a font with all available glyphs at once.
After analyzing the code, I realized that the
LoadFontEx
orLoadFontFromMemory
functions, when specifyingNULL, 0
for codepoints in the arguments, load only 95 glyphs (although according to the words from the cheatsheetI thought
default
was a full set of all available characters). But it turns out that to load fully all available glyphs, I have to manually collect an array of codepoints, but this is obviously very time-consuming and inconvenient.So I propose these two functions, which can be used to pre-count the number of available glyphs and automatically collect an array of codepoints. And then use them for
LoadFontEx
orLoadFontFromMemory
functions. For example like this:Of course, before writing these two functions, I tried changing the code of the
LoadFontEx
etc. functions (where I met places about the number of codepoints), so that when argumentsNULL, 0
were specified, the font would load all available glyphs/codepoints at once, not just 95 pieces, but it turned out to be not so simple. Besides, it wasn't good decision, because some glyphs were not loaded correctly, so I decided not to touch the existing code, and probably it's better to leave 95 glyphs for those who don't need Unicode.That's why it's better to first collect the necessary codepoints into an array and pass them when loading the font using additional functions, it's safer. And these two functions do it automatically and I didn't find any problems. At least the labels and text boxes in raygui display unicode glyphs well when typing text. I tried it on several fonts (only TTF though). I haven't done anything with the BDF type yet, because I just switched from 5.0 to 5.5 and discovered this new type, which honestly I've never heard of it before 🙂
Of course, we could just rasterize all 65536 possible glyphs of any font, but that's too memory expensive (if I understand correctly, empty glyphs will be rasterized as well). And these new functions allow to collect only the available glyphs in a font, not all 65536.
I don't know if you'll accept my PR, but I will definitely use these functions for myself, because fonts are different, and it's very inconvenient to choose codepoints for each random font. But stb_truetype still allows to pre-gather an array of codepoints before rasterization. Besides, I've seen enough requests for correct and automatic unicode text on the web. So it may be useful.