Chromium and FreeType

432 views
Skip to first unread message

WSK

unread,
Mar 14, 2022, 12:20:44 PM3/14/22
to Chromium-dev

I want to try to make chromium fonts less blurry without resorting to using patches to enable an old and problematic GDI that was removed ~50 versions ago. In the SKIA engine discussion group, I found information that you can try to use the backend freetype for this purpose (https://groups.google.com/g/skia-discuss/c/Z0WBnnxJTrk). And I don't quite understand how to do it. After looking at the source code, I found that different font managers are used for different operating systems. The default for Windows is SkFontMgr_New_DirectWrite(); But there is also SkFontMgr_New_Custom_Empty(); whose description reads:

/** Create a custom font manager that contains no built-in fonts. * This font manager uses FreeType for rendering. */

(https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/include/ports/SkFontMgr_empty.h)

Do I understand correctly that I need to replace the font manager?

By the way, I found a patch that includes opentype support, but it's already 3 years old and some files are no longer in the sources (https://codereview.chromium.org/2780133002/#ps140001).

Dominik Röttsches

unread,
Mar 15, 2022, 7:25:47 AM3/15/22
to 128...@gmail.com, Chromium-dev
Hi,

On Mon, Mar 14, 2022 at 6:20 PM WSK <128...@gmail.com> wrote:

I want to try to make chromium fonts less blurry without resorting to using patches to enable an old and problematic GDI that was removed ~50 versions ago. In the SKIA engine discussion group, I found information that you can try to use the backend freetype for this purpose (https://groups.google.com/g/skia-discuss/c/Z0WBnnxJTrk). And I don't quite understand how to do it. After looking at the source code, I found that different font managers are used for different operating systems. The default for Windows is SkFontMgr_New_DirectWrite(); But there is also SkFontMgr_New_Custom_Empty(); whose description reads:

/** Create a custom font manager that contains no built-in fonts. * This font manager uses FreeType for rendering. */

(https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/include/ports/SkFontMgr_empty.h)

If you see a particular blurriness issue, which you're referring to, I'd encourage you to file a bug if you have more details on that. 

If you wanted to render all fonts with FreeType and apply custom rendering settings, you can start at: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/fonts/web_font_typeface_factory.cc - where we have our logic for deciding which Skia backend to use for an individual web font depending on its font format. In WebFontTypefaceFactory we have logic for switching between FreeType and the native (CoreText, DWrite) backends by instantiating the font from the stream using different FontMgrs. The result is that for the font blob that's received a different Skia backend gets used, and different code is executed for metrics and rasterization.

However, doing that for system fonts on Windows, you would need to find a way to use DirectWriteFontProxy/DirectWriteFontProxyImpl for font matching, then extract the font blob data that DirectWrite gives you after font matching and then instantiate an SkTypeface using the SkFontMgr_Empty for that. That's harder and there's no pre-existing mechanism for that in the code, as for system fonts we always use the system rasterizers currently. 

Do I understand correctly that I need to replace the font manager?

See above. 

By the way, I found a patch that includes opentype support, but it's already 3 years old and some files are no longer in the sources (https://codereview.chromium.org/2780133002/#ps140001).

Chrome supports OpenType everywhere, variable fonts (as in this CL) are supported on Windows as web fonts as well. Variable fonts support for system fonts on Windows (like Bahnschrift) is limited. A variation of this change was later landed.

Dominik
Reply all
Reply to author
Forward
0 new messages