fontations icon indicating copy to clipboard operation
fontations copied to clipboard

[skrifa] support interpreter-version 35

Open mahkoh opened this issue 8 months ago • 24 comments

With this change, font rendering appears to be essentially identical to freetype.

Chromium compiled with this patch (and a small skia patch to use InterpreterVersion::from_environment):

image

Firefox:

image

There are some small differences but they might be caused by a different component.

I've not added any tests. Let me know if/how this should be tested.

Closes #1215

mahkoh avatar May 13 '25 17:05 mahkoh

It might also be necessary to round the font size somewhere. Otherwise fonts with fractional pixel sizes in chromium don't render correctly.

mahkoh avatar May 13 '25 17:05 mahkoh

I was able to fix the aforementioned issue by rounding font sizes when the interpreter version is 35. This makes chromium render text with fractional pixel sizes like firefox, that is, there is a hard jump at .5 and everything between x-0.5 and x+0.5 renders the same.

I believe that FreeType performs this rounding and that it does not depend on the interpreter version, but without interpreter-version=35 I could not easily spot the difference whereas interpreter-version=35 makes it obvious.

mahkoh avatar May 13 '25 20:05 mahkoh

Thank you for taking this on! I won’t be able to do a thorough review until next week but, at a glance, the code looks good and I don’t foresee any issues with landing this in some form.

dfrg avatar May 14 '25 21:05 dfrg

I just wanted to provide another data point for this: I just encountered a font that actually renders wrongly if hinting is disabled! If I don't enable hinting, the characters look like this, completely garbled:

image

With the current hinting mechanism, they look slightly better but still wrong: image

With your patch, they look correct: image

So this would definitely be nice having. :)

LaurenzV avatar Jun 08 '25 09:06 LaurenzV

For others, who arrive here looking for solution how to make font rendering beautiful again in Chrome 136+, now that the flags used to disable Fontation have been deprecated - you can still use google-chrome --disable-features=FontationsLinuxSystemFonts

This disables fontation and falls back to freetype so FREETYPE_PROPERTIES="truetype:interpreter-version=35" is respected again.

tarko avatar Jun 08 '25 11:06 tarko

I just wanted to provide another data point for this: I just encountered a font that actually renders wrongly if hinting is disabled! If I don't enable hinting, the characters look like this, completely garbled:

I believe this is #1303. For Skia/Chrome, we check the result of the require_interpreter() method and set the hinting target to Mono when that returns true. The result is very similar to the v35 interpreter.

dfrg avatar Jun 08 '25 12:06 dfrg

Ah interesting, will try that!

EDIT: Okay, can confirm that this fixes it, thanks for the hint!

LaurenzV avatar Jun 08 '25 12:06 LaurenzV

For others, who arrive here looking for solution how to make font rendering beautiful again in Chrome 136+, now that the flags used to disable Fontation have been deprecated - you can still use google-chrome --disable-features=FontationsLinuxSystemFonts

Note that this option is removed after 139.0.7258 https://chromiumdash.appspot.com/commit/2fc1ae192a45eb6f1716e232dd1626317f8d299e We no longer intend to carry the FreeType support.

See https://crbug.com/349952802 and reasoning in https://developer.chrome.com/blog/memory-safety-fonts#why_replace_freetype

drott avatar Jun 25 '25 10:06 drott

Then lot's hope this PR gets reviewed and merged until then.

I'll be out of the office during August so ideally that would happen before then.

mahkoh avatar Jun 26 '25 12:06 mahkoh

yes please

@drott, moving on from freetype is certainly good idea but don't leave us hanging here :)

tarko avatar Jun 26 '25 12:06 tarko

Ping

mahkoh avatar Aug 23 '25 06:08 mahkoh

It looks like this is still failing CI for the reason I mentioned above. I've made a PR to your PR which should fix it.

valadaptive avatar Aug 23 '25 20:08 valadaptive

I've merged your change but I don't think that is what has kept this PR from being reviewed.

mahkoh avatar Aug 24 '25 05:08 mahkoh

I don't think that is what has kept this PR from being reviewed

Apologies, will ask internally.

rsheeter avatar Aug 25 '25 15:08 rsheeter

https://issuetracker.google.com/issues/415076053 is marked WontFix, which I take to mean Chrome doesn't intend to work on this. Given that is there still a reason to land this?

rsheeter avatar Aug 25 '25 16:08 rsheeter

https://github.com/googlefonts/fontations/issues/1215 is still open. I believe various API consumers in the Rust text ecosystem also want this hinting style (e.g. https://github.com/dfrg/swash/issues/96).

This PR doesn't seem to introduce that much new code to test; it seems to be a few new branches in what is already a straight port of FreeType code. How much would it cost in code review time and ongoing maintenance burden?

valadaptive avatar Aug 25 '25 17:08 valadaptive

https://issuetracker.google.com/issues/415076053 is marked WontFix, which I take to mean Chrome doesn't intend to work on this. Given that is there still a reason to land this?

Doesn't it automatically fix it for chrome when it lands in fontations?

tarko avatar Aug 25 '25 17:08 tarko

How much would it cost in code review time and ongoing maintenance burden?

Little but not zero is probably fair?

Doesn't it automatically fix it for chrome when it lands in fontations?

I am under the impression Chrome would need code to activate it before it would do anything.

rsheeter avatar Aug 25 '25 17:08 rsheeter

https://issuetracker.google.com/issues/415076053 is marked WontFix, which I take to mean Chrome doesn't intend to work on this. Given that is there still a reason to land this?

It looks like the reason that issue was closed was because the author did not provide a justification for honoring FREETYPE_PROPERTIES=truetype:interpreter-version=35:

we no longer honor FREETYPE_PROPERTIES= - however, we do still take into account FontConfig rendering settings that are configured on the system.

What is the specific rendering issue you're trying to address with the FREETYPE_PROPERTIES environment variable? I suggest to file a specific issue for that.

kevina avatar Aug 25 '25 17:08 kevina

I am under the impression Chrome would need code to activate it before it would do anything.

Skia needs to call the function to load the interpreter version from the environment.

mahkoh avatar Aug 26 '25 03:08 mahkoh

https://github.com/googlefonts/fontations/issues/1215 is still open. I believe various API consumers in the Rust text ecosystem also want this hinting style (e.g. https://github.com/dfrg/swash/issues/96).

Vscode has also reverted the switch to fontations on their end due to the changed font rendering (linked above). So it's not just other rust code but also downstream from chromium.

mahkoh avatar Aug 26 '25 11:08 mahkoh

Electron due to chromium is also affected ofc, thats why I run slack and signal-desktop with --disable-features=FontationsLinuxSystemFonts as well

tarko avatar Aug 26 '25 12:08 tarko

Both the vscode and swash issues seem unrelated to the v35 interpreter. In the vscode case, this appears to be lack of support for embedded bitmaps. For swash, there is no way to request the monochrome hinting target and we don’t have a bi-level scanline converter with dropout control.

dfrg avatar Aug 26 '25 12:08 dfrg

Ping

mahkoh avatar Sep 23 '25 08:09 mahkoh

Could you please review this? It's only +234 −53 so it should not be that much work. The code is almost a 1-to-1 copy of the corresponding freetype code and can mostly be checked by comparing the two sources.

It would be one thing if you had said from the start that you don't want this. But instead you encouraged people that this is something that you supported.

I just don't want to have to have to recompile chromium just to get back the font rendering that I've enjoyed for the past 15 years.

mahkoh avatar Nov 29 '25 10:11 mahkoh

Yes, please

tarko avatar Nov 29 '25 11:11 tarko