Skip to content

Conversation

@DeeJayLSP
Copy link
Contributor

@DeeJayLSP DeeJayLSP commented Oct 9, 2025

Fixes font hinting for custom enabled character variations in TextServerAdvanced.

Before (uppercase i is a character variant from Inter):
before

After:
after

Does not affect character variations if enabled through the font file with font feature freeze, as they should be working properly by default. And doesn't matter in TextServerFallback as it doesn't support using font variations without font feature freeze anyway.

This is done by simply activating a define in FreeType and exposing HarfBuzz to it in the build scripts. FreeType's source code has the following comments regarding this:

FreeType uses the HarfBuzz library to improve auto-hinting of OpenType fonts. If available, many glyphs not directly addressable by a font's character map will be hinted also.

If FreeType gets compiled with FT_CONFIG_OPTION_USE_HARFBUZZ to make the HarfBuzz library access OpenType features for getting better glyph coverages, this property sets the (auto-fitter) script to be used for the default (OpenType) script data of a font's GSUB table. Features for the default script are intended for all scripts not explicitly handled in GSUB; an example is a 'dlig' feature, containing the combination of the characters 'T', 'E', and 'L' to form a 'TEL' ligature.

If accepted, this would allow #111140 to enable more variants without having to resort to font feature freezes.

I found this by compiling the engine with builtin_freetype=no and noticing the hinting fixed, as Arch Linux's FreeType is linked with HarfBuzz.

@DeeJayLSP DeeJayLSP requested a review from a team as a code owner October 9, 2025 21:08
@DeeJayLSP DeeJayLSP force-pushed the fthb branch 2 times, most recently from d960c6a to 1c4e6bb Compare October 9, 2025 21:11
@Calinou Calinou added this to the 4.x milestone Oct 9, 2025
@DeeJayLSP DeeJayLSP changed the title Use HarfBuzz for font hinting when available Use HarfBuzz for font shaping when available Oct 9, 2025
@DeeJayLSP DeeJayLSP changed the title Use HarfBuzz for font shaping when available Use HarfBuzz for improved font shaping when available Oct 9, 2025
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

Since we do include HarfBuzz there's no reason not to enable it.

Not sure if there's any point for making it a separate module, TextServerFallback should not be able to use any OT features, so it should not do anything.

@DeeJayLSP
Copy link
Contributor Author

DeeJayLSP commented Oct 10, 2025

Not sure if there's any point for making it a separate module, TextServerFallback should not be able to use any OT features, so it should not do anything.

Note that you can enable character variants within the font file itself, and they should show up even when using TextServerFallback. I tested this with Adwaita Sans (GNOME's font which is just Inter with tailed lowercase L enabled).

And they will be broken anyway if FreeType isn't using HarfBuzz. Apparently not?

Edit: It seems like freezing font features bypasses the need for HarfBuzz. Still a good thing to implement as it "fixes" custom font feature usage.

@DeeJayLSP
Copy link
Contributor Author

DeeJayLSP commented Oct 10, 2025

Shouldn't this be labelled as a bug? Because technically:

  • variation enabled through code or setting: broken hinting
  • variation enabled through font feature freeze: working properly

Technically, the end user having to resort to font feature freeze would be considered a workaround for this.

@DeeJayLSP DeeJayLSP changed the title Use HarfBuzz for improved font shaping when available Use HarfBuzz to fix variant shaping in TextServerAdvanced Oct 10, 2025
@DeeJayLSP DeeJayLSP changed the title Use HarfBuzz to fix variant shaping in TextServerAdvanced Use HarfBuzz to fix variant hinting in TextServerAdvanced Oct 10, 2025
@Repiteo Repiteo modified the milestones: 4.x, 4.6 Oct 13, 2025
@Repiteo Repiteo merged commit 3dbd7d3 into godotengine:master Oct 14, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 14, 2025

Thanks!

@DeeJayLSP DeeJayLSP deleted the fthb branch October 14, 2025 01:20
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.

4 participants