SDL2_ttf supports rendering complex and right-to-left-written scripts (at least in the versions based on Harfbuzz) but one thing I can’t find is a way to position the caret (text cursor) within such a string - or equivalently how to highlight part of a string.
To do that one needs knowledge of the position of each character in the string (which will typically be different from their positions when only part of the string is rendered, because of the behavior of complex scripts).
In Windows this is achieved using the ScriptStringCPtoX()
function, which converts a character index to a pixel offset. But I can’t find any equivalent in SDL2_ttf. This would seem to be a vital function, am I missing something?
No suggestions? Even the most basic text-editing capability (for example, in the context of a game, editing one’s name in a high-score table) requires the ability to position the text cursor (caret) within a rendered string.
In the case of a complex script, like Arabic, this is non-trivial and only the text-shaping engine (e.g. Harfbuzz) has the necessary information. Yet, as far as I can see, this capability isn’t exposed by SDL2_ttf at all.
SDL2 supposedly takes ‘internationalization’ seriously, in supporting Unicode (UTF-8) strings and complex scripts, but with such a key feature missing - if indeed it is - it cannot make that claim.
This definitely seems like an oversight. Feel free to create a PR that adds the functionality you need.
Thanks!
I don’t have the understanding of SDL2_ttf and Harfbuzz which would be needed. Google suggests that HarfBuzz.buffer_get_glyph_positions()
might be helpful.