-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to fall back through multiple fonts if required #362
Comments
If this is out-of-scope for SDL_ttf, then a SDL + Pango wrapper might be an alternative. Unfortunately, "the" SDL + Pango wrapper is stuck in SDL 1.2, with at least two competing forks updating it to SDL 2, and no SDL 3 version that I'm aware of: more information in https://discourse.libsdl.org/t/moving-sdl-pango-to-the-libsdl-org-github-organisation/30886/6. |
SDL_ttf only knows about the font that you've provided, and only allows one font in a single text output pass. This definitely seems like something we should remedy in SDL_ttf 3.0 |
OK, so are you saying this is out-of-scope (working as intended) in SDL_ttf 2.0; but in-scope (actionable feature request) for SDL_ttf 3.0? |
Yes, that's correct. |
Having multiple fonts can solve "tofu". but actually, it's not the only issue. If you have a string with "some latin chars ... some arabic chars.. " you probably have to use multiple fonts, but also change left-to-right and right-to-left rendering. There was some issue/patch, but only using 1 font (and so not fixing the tofu things): #66 and #135 I think this can be solved on top of current SDL_ttf API. eg: interesting links: |
@smcv, I'm updating SDL_ttf for SDL 3.0 now, and this is one of the two big things left. I think solving the multiple font problem can be done independently of the other things @1bsyl raised above. Here's some info on how you can handle multiple fonts with harfbuzz: |
This is really a feature request/limitation, but I'll write the issue template as though it was a bug, because that makes it easier to see what's going on. It might be a duplicate of #338, but it isn't 100% clear to me what the scope of #338 is, so I'm erring on the side of opening a separate issue (which can easily be closed as a duplicate if necessary) instead of replying to an existing issue.
This was originally ValveSoftware/Source-1-Games#6058, but that issue report is clouded by implementation details of a workaround that the user had previously used, and speculation about it potentially being a bug/limitation of Steam Linux Runtime containers.
Steps to reproduce the limitation
fonts-noto-core
on Debian/Ubuntu.Noto Sans
in variantRegular
, which is the default font used when most modern Linux distros ask fontconfig for asans-serif
font.Noto Sans
covers simple alphabet-based writing systems used in Europe (Latin, Greek, Cyrillic) but it does not cover e.g. Arabic, Hebrew, Sinhala or Thai.Noto Sans Hebrew
andNoto Sans Sinhala
, again with aRegular
variant. These fonts cover the extra glyphs required to write in non-European languages.Ctrl+Shift+U, 0, d, 9, e, Space
(hopefully the same in other desktop environments like KDE Plasma, I haven't tried). You could probably get similar results with Arabic, Hebrew or Thai, but Arabic and Hebrew are right-to-left languages which have their own unique display issues, so using Sinhala as our example might be best.steam-runtime-dialog-ui
:sans-serif
, but I could have usedNoto Sans
(ttf_load_font()
in https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/steam-runtime-tools/sdl-utils.c?ref_type=heads)dialog_set_message()
in https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/bin/dialog-ui.c?ref_type=heads which callsTTF_RenderUTF8_Blended_Wrapped()
)I do not have access to TF2 source code, but I suspect it might be doing something rather similar.
You can try this on any Linux system with Steam installed by running:
where
~/tmp/sinhala.txt
contains the desired text.Expected result
Ideally, if I try to render a glyph that is not available in
Noto Sans
, there should be a way to fall back to fetching that glyph from related fonts likeNoto Sans Sinhala
, or (as a last resort) from any installed font with no restrictions - displaying text in a style that doesn't match how we display Latin is better than displaying placeholder boxes.Actual result
If the desired glyph is not available in
Noto Sans
, there is no straightforward way to fall back toNoto Sans Sinhala
, and instead SDL_ttf renders a placeholder rectangle ("tofu").Non-SDL implementation of expected result
To prove that it's possible:
zenity --info --text="$(cat ~/tmp/sinhala.txt)"
, where~/tmp/sinhala.txt
contains the desired textThe text was updated successfully, but these errors were encountered: