godot
godot copied to clipboard
Use system fonts as fallback.
- Add support for font weight and stretch selection when using system fonts.
- Add OS function to get system fallback font from a font name, text, and language code (
OS.get_system_font_path_for_text). - Automatically use system fonts as fallback (as a last resort, after all user specified fallback fonts fail), system font is selected by OS, based on the main font name and style.
Implemented on Android, iOS, Linux (fontconfig required), macOS, and Windows.
For the reference: Implementing it for Web is only possible with https://wicg.github.io/local-font-access/ (draft proposal, not supported by anything).
Test Project: FontSelect.zip
Performance seems to be pretty reasonable, font lookup takes about 100-1500 μs (every time text with the missing glyphs is shaped, Linux version is the slowest). Loading all fonts for the sample on the screenshot (6 to 10 fonts depending on OS) takes about 15000 μs on average. So should be fine for UI apps (or as fallback anywhere).
Screenshots
| Linux (Pop!_OS 22.04) | ![]() |
| macOS 13.0.1 | ![]() |
| Windows 11 | ![]() |
| Android 12 | ![]() |
It's not a clean OS install, so the default font set might be different.
Thanks!
I believe this changes "fontconfig" from optional to required on Linux. I'm not debugging my (build) system today.
I believe this changes "fontconfig" from optional to required on Linux. I'm not debugging my (build) system today.
It should not, but I think I have missed ifdef for the helper functions, will fix in a moment.
Nice feature. Will it back port to 3.x?
Nice feature. Will it back port to 3.x?
System font support relies on a lot of backwards-incompatible TextServer changes, so it's not possible to backport this feature to 3.x without a complete rewrite.



