#GitHub - noaccessl/glua-VisualCharacterH...
1 messages · Page 1 of 1 (latest)
I wonder if it would be faster to cache individual character sizes for each font and use those to determine the height of a given string
There may also be potential in keeping track of which character is the tallest for each font, then simply checking if the string contains that character. If it does you can just return that character's height instead of checking each character in the string
I'm generally assuming that the most expensive part of this process is always capturing the pixels and iterating over them
this is 100% supported in my imgui-lua + gmod backend impl. i even ported stb_truetype. it's quite sad that gmod provides little support for fonts in terms lua api
It is. That was the reason behind adding caching.
That would increase the complexity rather significantly, I guess.
The intent is on using that for known, certain texts.
And if a text changes dynamically, one could pick a particular character/sequence for this whole text. For instance, the 'W' character, or this "ABC" sequence, or this "|q" sequence.
But low-weight image-formats should probably lower the cost of capturing the pixels, presumably.
Also, without cache it was dropping fps significantly if called every frame plus multiple times.
So at this point the current solution is quite optimal and broadly suitable, in my view. One should have some resourcefulness.
I don’t know that it would be much more complex. Split string, iterate over characters, check each character height in cache (populate if missing) and keep track of the largest height seen
If you prefer to leave the optimization to users that’s reasonable, but I think complexity is not the issue