godot icon indicating copy to clipboard operation
godot copied to clipboard

Use system fonts as fallback.

Open bruvzg opened this issue 3 years ago • 1 comments

  • 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

bruvzg avatar Nov 22 '22 08:11 bruvzg

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) linux
macOS 13.0.1 macos
Windows 11 win11
Android 12 android

It's not a clean OS install, so the default font set might be different.

bruvzg avatar Nov 23 '22 07:11 bruvzg

Thanks!

akien-mga avatar Dec 04 '22 23:12 akien-mga

I believe this changes "fontconfig" from optional to required on Linux. I'm not debugging my (build) system today.

fire avatar Dec 05 '22 04:12 fire

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.

bruvzg avatar Dec 05 '22 05:12 bruvzg

Nice feature. Will it back port to 3.x?

alexzheng avatar Dec 11 '22 06:12 alexzheng

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.

Calinou avatar Dec 11 '22 16:12 Calinou