Skip to content
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

Use system fonts as fallback. #68995

Merged
merged 1 commit into from
Dec 4, 2022
Merged

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Nov 22, 2022

  • 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
Copy link
Member Author

bruvzg commented Nov 23, 2022

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 bruvzg force-pushed the sys_font_for_text branch 10 times, most recently from 78ba345 to 0727172 Compare November 27, 2022 14:13
@bruvzg bruvzg changed the title [WIP] Use system fonts as fallback. Use system fonts as fallback. Nov 27, 2022
@bruvzg bruvzg force-pushed the sys_font_for_text branch 3 times, most recently from 8839f59 to 3343ee2 Compare November 28, 2022 07:39
@bruvzg bruvzg marked this pull request as ready for review November 28, 2022 08:42
@bruvzg bruvzg requested a review from a team as a code owner November 28, 2022 08:42
@bruvzg bruvzg requested review from a team as code owners November 28, 2022 08:42
servers/text_server.h Outdated Show resolved Hide resolved
core/io/file_access.cpp Outdated Show resolved Hide resolved
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

There's a suggestion from KoBeWi for the new File API, to be discussed. Otherwise the rest should be good to merge.

Add support for font weight and stretch selection when using system fonts.
Add function to get system fallback font from a font name, style, text, and language code.
Implement system font support for Android.
Use system fonts as a last resort fallback.
@bruvzg bruvzg force-pushed the sys_font_for_text branch from 29a7216 to ecec415 Compare December 4, 2022 16:54
Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Android section looks good to me.

@akien-mga akien-mga merged commit a0365c1 into godotengine:master Dec 4, 2022
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga modified the milestones: 4.x, 4.0 Dec 4, 2022
@fire
Copy link
Member

fire commented Dec 5, 2022

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

@bruvzg bruvzg deleted the sys_font_for_text branch December 5, 2022 05:57
@bruvzg
Copy link
Member Author

bruvzg commented Dec 5, 2022

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.

@alexzheng
Copy link

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

@Calinou
Copy link
Member

Calinou commented Dec 11, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants