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

Prefer family name in fonts' names table #89817

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

timothyqiu
Copy link
Member

@timothyqiu timothyqiu commented Mar 23, 2024

Currently, family_name is used as a font's name. This field is an ASCII string, but

In case the font doesn't provide a specific family name entry, FreeType tries to synthesize one, deriving it from other name entries.

FreeType converts non-ASCII characters into question marks ("?") in this process, resulting in unreadable names for some fonts.

This PR prioritizes reading SFNT names (the name table of TrueType and OpenType fonts) to avoid possible question marks. English (US) is still preferred, so it's mostly compatible.

Among possible encodings, UTF-16 is the most common one that Godot's String supports. But it's always in big endian, so I added an extra parameter to String::parse_utf16() to specify the endianness to use when no BOM is present.

@timothyqiu
Copy link
Member Author

Added the same logic in TextServerFallback.

Using hb_ot_name_get_utf32 in TextServerAdvanced does make decoding easier 🎉

@timothyqiu timothyqiu requested a review from bruvzg March 31, 2024 10:15
modules/text_server_fb/text_server_fb.cpp Outdated Show resolved Hide resolved
modules/text_server_fb/text_server_fb.cpp Outdated Show resolved Hide resolved
@timothyqiu timothyqiu force-pushed the better-family-name branch from c9dbe31 to 242a417 Compare April 6, 2024 08:05
@timothyqiu
Copy link
Member Author

Added the check for BIG_ENDIAN_ENABLED inside String::parse_utf16().

@timothyqiu timothyqiu force-pushed the better-family-name branch from 242a417 to 9bcda8f Compare April 6, 2024 08:09
@akien-mga akien-mga merged commit 4e45511 into godotengine:master Apr 6, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@timothyqiu timothyqiu deleted the better-family-name branch April 6, 2024 11:12
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.

3 participants