Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c18d3df

Browse files
authored
Replace all calls to SkTypeface::Make with SkFontMgr ones (#48319)
Similar to #48179, Flutter needs to stop depending on the default font manager, which the `SkTypeface::Make*` calls do implicitly ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 1caa747 commit c18d3df

File tree

15 files changed

+57
-15
lines changed

15 files changed

+57
-15
lines changed

display_list/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ if (enable_unittests) {
158158
"//flutter/display_list/testing:display_list_testing",
159159
"//flutter/impeller/typographer/backends/skia:typographer_skia_backend",
160160
"//flutter/testing",
161+
"//flutter/third_party/txt",
161162
]
162163

163164
if (!defined(defines)) {

display_list/testing/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ source_set("display_list_testing") {
1717
deps = [
1818
"//flutter/skia",
1919
"//flutter/testing:testing_lib",
20+
"//flutter/third_party/txt",
2021
]
2122

2223
public_deps = [ "//flutter/display_list:display_list" ]

display_list/testing/dl_rendering_unittests.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@
2323

2424
#include "third_party/skia/include/core/SkBBHFactory.h"
2525
#include "third_party/skia/include/core/SkColorFilter.h"
26+
#include "third_party/skia/include/core/SkFontMgr.h"
2627
#include "third_party/skia/include/core/SkPictureRecorder.h"
2728
#include "third_party/skia/include/core/SkStream.h"
2829
#include "third_party/skia/include/core/SkSurface.h"
30+
#include "third_party/skia/include/core/SkTypeface.h"
2931
#include "third_party/skia/include/effects/SkGradientShader.h"
3032
#include "third_party/skia/include/effects/SkImageFilters.h"
3133
#include "third_party/skia/include/encode/SkPngEncoder.h"
3234
#include "third_party/skia/include/gpu/GrDirectContext.h"
3335
#include "third_party/skia/include/gpu/GrRecordingContext.h"
3436
#include "third_party/skia/include/gpu/GrTypes.h"
37+
#include "txt/platform.h"
3538

3639
namespace flutter {
3740
namespace testing {
@@ -2747,7 +2750,8 @@ class CanvasCompareTester {
27472750

27482751
static sk_sp<SkTextBlob> MakeTextBlob(const std::string& string,
27492752
SkScalar font_height) {
2750-
SkFont font(SkTypeface::MakeFromName("ahem", SkFontStyle::Normal()),
2753+
SkFont font(txt::GetDefaultFontManager()->matchFamilyStyle(
2754+
"ahem", SkFontStyle::Normal()),
27512755
font_height);
27522756
return SkTextBlob::MakeFromText(string.c_str(), string.size(), font,
27532757
SkTextEncoding::kUTF8);

display_list/testing/dl_test_snippets.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "flutter/display_list/testing/dl_test_snippets.h"
66
#include "flutter/display_list/dl_builder.h"
77
#include "flutter/display_list/dl_op_receiver.h"
8+
#include "third_party/skia/include/core/SkFontMgr.h"
9+
#include "third_party/skia/include/core/SkTypeface.h"
10+
#include "txt/platform.h"
811

912
namespace flutter {
1013
namespace testing {
@@ -978,7 +981,7 @@ SkFont CreateTestFontOfSize(SkScalar scalar) {
978981
static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
979982
auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
980983
FML_CHECK(mapping);
981-
return SkFont{SkTypeface::MakeFromData(mapping), scalar};
984+
return SkFont{txt::GetDefaultFontManager()->makeFromData(mapping), scalar};
982985
}
983986

984987
sk_sp<SkTextBlob> GetTestTextBlob(int index) {

flow/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ source_set("flow") {
9494
"//flutter/common/graphics",
9595
"//flutter/display_list",
9696
"//flutter/fml",
97+
"//flutter/third_party/txt",
9798
]
9899

99100
deps = [ "//flutter/skia" ]

flow/layers/performance_overlay_layer.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#include "flow/stopwatch_dl.h"
1414
#include "flow/stopwatch_sk.h"
1515
#include "third_party/skia/include/core/SkFont.h"
16+
#include "third_party/skia/include/core/SkFontMgr.h"
1617
#include "third_party/skia/include/core/SkTextBlob.h"
18+
#include "third_party/skia/include/core/SkTypeface.h"
19+
#include "txt/platform.h"
1720
#ifdef IMPELLER_SUPPORTS_RENDERING
1821
#include "impeller/typographer/backends/skia/text_frame_skia.h" // nogncheck
1922
#endif // IMPELLER_SUPPORTS_RENDERING
@@ -72,7 +75,8 @@ sk_sp<SkTextBlob> PerformanceOverlayLayer::MakeStatisticsText(
7275
const std::string& font_path) {
7376
SkFont font;
7477
if (font_path != "") {
75-
font = SkFont(SkTypeface::MakeFromFile(font_path.c_str()));
78+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
79+
font = SkFont(font_mgr->makeFromFile(font_path.c_str()));
7680
}
7781
font.setSize(15);
7882

impeller/aiks/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impeller_component("aiks_unittests") {
8888
"//flutter/impeller/scene",
8989
"//flutter/impeller/typographer/backends/stb:typographer_stb_backend",
9090
"//flutter/testing:testing_lib",
91+
"//flutter/third_party/txt",
9192
]
9293

9394
if (!impeller_trace_canvas) {
@@ -119,6 +120,7 @@ impeller_component("aiks_unittests_golden") {
119120
"//flutter/impeller/scene",
120121
"//flutter/impeller/typographer/backends/stb:typographer_stb_backend",
121122
"//flutter/testing:testing_lib",
123+
"//flutter/third_party/txt",
122124
]
123125
}
124126

impeller/aiks/aiks_unittests.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#include "impeller/typographer/backends/stb/typographer_context_stb.h"
4747
#include "third_party/imgui/imgui.h"
4848
#include "third_party/skia/include/core/SkData.h"
49+
#include "third_party/skia/include/core/SkFontMgr.h"
50+
#include "third_party/skia/include/core/SkTypeface.h"
51+
#include "txt/platform.h"
4952

5053
namespace impeller {
5154
namespace testing {
@@ -1398,7 +1401,8 @@ bool RenderTextInCanvasSkia(const std::shared_ptr<Context>& context,
13981401
if (!mapping) {
13991402
return false;
14001403
}
1401-
SkFont sk_font(SkTypeface::MakeFromData(mapping), options.font_size);
1404+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
1405+
SkFont sk_font(font_mgr->makeFromData(mapping), options.font_size);
14021406
auto blob = SkTextBlob::MakeFromString(text.c_str(), sk_font);
14031407
if (!blob) {
14041408
return false;
@@ -1576,7 +1580,8 @@ TEST_P(AiksTest, CanRenderTextOutsideBoundaries) {
15761580
ASSERT_NE(mapping, nullptr);
15771581

15781582
Scalar font_size = 80;
1579-
SkFont sk_font(SkTypeface::MakeFromData(mapping), font_size);
1583+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
1584+
SkFont sk_font(font_mgr->makeFromData(mapping), font_size);
15801585

15811586
Paint text_paint;
15821587
text_paint.color = Color::Blue().WithAlpha(0.8);
@@ -3449,7 +3454,8 @@ TEST_P(AiksTest, TextForegroundShaderWithTransform) {
34493454
ASSERT_NE(mapping, nullptr);
34503455

34513456
Scalar font_size = 100;
3452-
SkFont sk_font(SkTypeface::MakeFromData(mapping), font_size);
3457+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
3458+
SkFont sk_font(font_mgr->makeFromData(mapping), font_size);
34533459

34543460
Paint text_paint;
34553461
text_paint.color = Color::Blue();

impeller/display_list/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impeller_component("display_list_unittests") {
6363
"../playground:playground_test",
6464
"//flutter/impeller/scene",
6565
"//flutter/impeller/typographer/backends/stb:typographer_stb_backend",
66+
"//flutter/third_party/txt",
6667
]
6768

6869
if (!defined(defines)) {

impeller/display_list/dl_playground.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
1111
#include "third_party/imgui/imgui.h"
1212
#include "third_party/skia/include/core/SkData.h"
13+
#include "third_party/skia/include/core/SkFontMgr.h"
14+
#include "third_party/skia/include/core/SkTypeface.h"
15+
#include "txt/platform.h"
1316

1417
namespace impeller {
1518

@@ -56,7 +59,8 @@ SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) {
5659
static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
5760
auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
5861
FML_CHECK(mapping);
59-
return SkFont{SkTypeface::MakeFromData(mapping), scalar};
62+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
63+
return SkFont{font_mgr->makeFromData(mapping), scalar};
6064
}
6165

6266
SkFont DlPlayground::CreateTestFont() {

impeller/typographer/typographer_unittests.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "third_party/skia/include/core/SkFontMgr.h"
1313
#include "third_party/skia/include/core/SkRect.h"
1414
#include "third_party/skia/include/core/SkTextBlob.h"
15+
#include "third_party/skia/include/core/SkTypeface.h"
1516
#include "txt/platform.h"
1617

1718
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
@@ -94,7 +95,8 @@ TEST_P(TypographerTest, LazyAtlasTracksColor) {
9495
auto mapping = flutter::testing::OpenFixtureAsSkData("NotoColorEmoji.ttf");
9596
#endif
9697
ASSERT_TRUE(mapping);
97-
SkFont emoji_font(SkTypeface::MakeFromData(mapping), 50.0);
98+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
99+
SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0);
98100
SkFont sk_font;
99101

100102
auto blob = SkTextBlob::MakeFromString("hello", sk_font);

lib/ui/text/asset_manager_font_provider.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
#include "flutter/fml/logging.h"
1010
#include "third_party/skia/include/core/SkData.h"
11+
#include "third_party/skia/include/core/SkFontMgr.h"
1112
#include "third_party/skia/include/core/SkStream.h"
1213
#include "third_party/skia/include/core/SkString.h"
1314
#include "third_party/skia/include/core/SkTypeface.h"
15+
#include "txt/platform.h"
1416

1517
namespace flutter {
1618

@@ -116,8 +118,9 @@ auto AssetManagerFontStyleSet::createTypeface(int i) -> CreateTypefaceRet {
116118
MappingReleaseProc, asset_mapping_ptr);
117119
std::unique_ptr<SkMemoryStream> stream = SkMemoryStream::Make(asset_data);
118120

121+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
119122
// Ownership of the stream is transferred.
120-
asset.typeface = SkTypeface::MakeFromStream(std::move(stream));
123+
asset.typeface = font_mgr->makeFromStream(std::move(stream));
121124
if (!asset.typeface) {
122125
FML_DLOG(ERROR) << "Unable to load font asset for family: "
123126
<< family_name_;

lib/ui/text/font_collection.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include "third_party/tonic/logging/dart_invoke.h"
2222
#include "third_party/tonic/typed_data/typed_list.h"
2323
#include "txt/asset_font_manager.h"
24+
#include "txt/platform.h"
2425
#include "txt/test_font_manager.h"
26+
2527
#if FML_OS_MACOSX || FML_OS_IOS
2628
#include "txt/platform_mac.h"
2729
#endif
@@ -158,8 +160,8 @@ void FontCollection::LoadFontFromList(Dart_Handle font_data_handle,
158160

159161
std::unique_ptr<SkStreamAsset> font_stream = std::make_unique<SkMemoryStream>(
160162
font_data.data(), font_data.num_elements(), true);
161-
sk_sp<SkTypeface> typeface =
162-
SkTypeface::MakeFromStream(std::move(font_stream));
163+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
164+
sk_sp<SkTypeface> typeface = font_mgr->makeFromStream(std::move(font_stream));
163165
txt::TypefaceFontAssetProvider& font_provider =
164166
font_collection.dynamic_font_manager_->font_provider();
165167
if (family_name.empty()) {

runtime/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ source_set("test_font") {
1010
"test_font_data.cc",
1111
"test_font_data.h",
1212
]
13-
deps = [ "//flutter/skia" ]
13+
deps = [
14+
"//flutter/skia",
15+
"//flutter/third_party/txt",
16+
]
1417
public_configs = [ "//flutter:config" ]
1518
defines = []
1619
if (flutter_runtime_mode == "debug" || current_toolchain == host_toolchain) {

runtime/test_font_data.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646

4747
#if EMBED_TEST_FONT_DATA
4848

49+
#include "third_party/skia/include/core/SkFontMgr.h"
50+
#include "third_party/skia/include/core/SkTypeface.h"
51+
#include "txt/platform.h"
52+
4953
static const unsigned char kAhemFont[] = {
5054
0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x80, 0x00, 0x03, 0x00, 0x30,
5155
0x4f, 0x53, 0x2f, 0x32, 0x77, 0x60, 0xf9, 0x6f, 0x00, 0x00, 0x01, 0x38,
@@ -1621,11 +1625,12 @@ namespace flutter {
16211625
std::vector<sk_sp<SkTypeface>> GetTestFontData() {
16221626
std::vector<sk_sp<SkTypeface>> typefaces;
16231627
#if EMBED_TEST_FONT_DATA
1624-
typefaces.push_back(SkTypeface::MakeFromStream(
1628+
sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
1629+
typefaces.push_back(font_mgr->makeFromStream(
16251630
SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength)));
1626-
typefaces.push_back(SkTypeface::MakeFromStream(
1631+
typefaces.push_back(font_mgr->makeFromStream(
16271632
SkMemoryStream::MakeDirect(kAhemFont, kAhemFontLength)));
1628-
typefaces.push_back(SkTypeface::MakeFromStream(
1633+
typefaces.push_back(font_mgr->makeFromStream(
16291634
SkMemoryStream::MakeDirect(kCoughFont, kCoughFontLength)));
16301635
#endif // EMBED_TEST_FONT_DATA
16311636
return typefaces;

0 commit comments

Comments
 (0)