grimfang4 / SDL_FontCache

A generic font caching C library with loading and rendering support for SDL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Line splitting in FC_DrawBox (and variants)

TG-Galeforce opened this issue · comments

I'm currently working on supporting Japanese text in one of my games. The Japanese language does not use spaces, and therefore FC_DrawBox puts long bodies of text into one line instead of splitting them. Thus, I'd like to know where the line splitting happens in your code so that I can modify that functionality to start new lines at arbitrary characters (instead of just whitespace) if the language is Japanese. Can you please point me to where I should look? Thank you in advance.

Fortunately, I just touched this with the last changeset and made it easier to extend. Look at SDL_FontCache.c lines 1066 and 1885. For a general solution, I would think that a customizable array of word-breaking characters would work well.

For Japanese, it might just be best to add an option to break on every character.

Ah, thank you for addressing this! For some reason, I was never alerted of your reply, so I didn't know until now that you'd done it...please accept my very belated gratitude.

No problem. :)
For reference, that commit was f1a3480, where a utility function was added to detect and preserve breaking spaces that FC_GetBufferFitToColumn() would use instead of assuming " ". The next step would be to either hardcode your own breaking space characters (find "Add any characters here that should make separate words") or add functions/options to specify the characters or that all characters should break words.

Understood; I will try these steps. Thank you again.