0

[Fontations] Flag to switch system fonts, Chrome UI font to Fontations

Introduce switch and configure system font instantiation with
a FontScanner to ensure that instantiation happens through
Fontations instead of FreeType.

The outcome of this change has been tested in [1]: If this flag is
switched on, Linux system font in content and in the Chrome browser UI
on Linux and ChromeOS will move to being rendered by Fontations. This
can mean tiny pixel changes in antialiasing, but from a user experience
point of view, this is intended as an unnoticeable change.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/6169919

Bug: chromium:346918516
Change-Id: Id4ae3094083c9b964854c5e7cef31dc6c6907e29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6286047
Reviewed-by: Ben Wagner <bungeman@google.com>
Auto-Submit: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
Cr-Commit-Position: refs/heads/main@{#1424559}
This commit is contained in:
Dominik Röttsches
2025-02-25 08:10:12 -08:00
committed by Chromium LUCI CQ
parent 1f4cd39ed2
commit 493caf92f7
6 changed files with 62 additions and 3 deletions

@ -242,6 +242,7 @@ component("skia") {
"ext/skia_memory_dump_provider.h",
"ext/skia_trace_memory_dump_impl.h",
"ext/skia_utils_base.h",
"fontations_feature.h",
"rusty_png_feature.h",
]
sources = [
@ -273,6 +274,7 @@ component("skia") {
"ext/skia_memory_dump_provider.cc",
"ext/skia_trace_memory_dump_impl.cc",
"ext/skia_utils_base.cc",
"fontations_feature.cc",
"rusty_png_feature.cc",
]
if (is_ios) {

@ -6,6 +6,7 @@
#include "base/check.h"
#include "build/build_config.h"
#include "skia/fontations_feature.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkRefCnt.h"
@ -22,6 +23,7 @@
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#include "third_party/skia/include/ports/SkFontMgr_FontConfigInterface.h"
#include "third_party/skia/include/ports/SkFontScanner_Fontations.h"
#endif
#if BUILDFLAG(IS_FUCHSIA)
@ -62,7 +64,13 @@ static sk_sp<SkFontMgr> fontmgr_factory() {
return SkFontMgr_New_CoreText(nullptr);
#elif BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
return fci ? SkFontMgr_New_FCI(std::move(fci)) : nullptr;
if (base::FeatureList::IsEnabled(skia::kFontationsLinuxSystemFonts)) {
return fci ? SkFontMgr_New_FCI(std::move(fci),
SkFontScanner_Make_Fontations())
: nullptr;
} else {
return fci ? SkFontMgr_New_FCI(std::move(fci)) : nullptr;
}
#elif BUILDFLAG(IS_FUCHSIA)
fuchsia::fonts::ProviderSyncPtr provider;
base::ComponentContextForProcess()->svc()->Connect(provider.NewRequest());

@ -0,0 +1,14 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "skia/fontations_feature.h"
namespace skia {
// Instantiate system fonts on Linux with Fontations, affects
// SkFontMgr instantiation in skia/ext/font_utils.cc
BASE_FEATURE(kFontationsLinuxSystemFonts,
"FontationsLinuxSystemFonts",
base::FEATURE_DISABLED_BY_DEFAULT);
} // namespace skia

17
skia/fontations_feature.h Normal file

@ -0,0 +1,17 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKIA_FONTATIONS_FEATURE_H_
#define SKIA_FONTATIONS_FEATURE_H_
#include "base/feature_list.h"
#include "third_party/skia/include/private/base/SkAPI.h"
namespace skia {
SK_API BASE_DECLARE_FEATURE(kFontationsLinuxSystemFonts);
}
#endif // SKIA_FONTATIONS_FEATURE_H_

@ -72,6 +72,7 @@ include_rules = [
"+services/viz/public/mojom/compositing/compositor_frame_sink.mojom-blink.h",
"+services/viz/public/mojom/hit_test/input_target_client.mojom-blink.h",
"+skia/ext",
"+skia/fontations_feature.h",
#TODO(nverne): remove this
"+third_party/blink/public/web/blink.h",
"+third_party/ced/src/compact_enc_det/compact_enc_det.h",

@ -7,9 +7,15 @@
#include "base/notreached.h"
#include "build/build_config.h"
#include "skia/ext/font_utils.h"
#include "skia/fontations_feature.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_WIN) && \
!BUILDFLAG(IS_FUCHSIA)
#include "third_party/skia/include/ports/SkFontMgr_Fontations.h"
#endif
namespace blink {
// static
@ -22,7 +28,12 @@ sk_sp<SkTypeface> SkTypeface_Factory::FromFontConfigInterfaceIdAndTtcIndex(
SkFontConfigInterface::FontIdentity font_identity;
font_identity.fID = config_id;
font_identity.fTTCIndex = ttc_index;
return fci->makeTypeface(font_identity, skia::DefaultFontMgr());
if (base::FeatureList::IsEnabled(skia::kFontationsLinuxSystemFonts)) {
return fci->makeTypeface(font_identity, SkFontMgr_New_Fontations_Empty());
} else {
return fci->makeTypeface(font_identity, skia::DefaultFontMgr());
}
#else
NOTREACHED();
#endif
@ -34,7 +45,13 @@ sk_sp<SkTypeface> SkTypeface_Factory::FromFilenameAndTtcIndex(
int ttc_index) {
#if !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_FUCHSIA) && \
!BUILDFLAG(IS_APPLE)
return skia::DefaultFontMgr()->makeFromFile(filename.c_str(), ttc_index);
if (base::FeatureList::IsEnabled(skia::kFontationsLinuxSystemFonts)) {
return SkFontMgr_New_Fontations_Empty()->makeFromFile(filename.c_str(),
ttc_index);
} else {
return skia::DefaultFontMgr()->makeFromFile(filename.c_str(), ttc_index);
}
#else
NOTREACHED();
#endif