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

Commit abaac56

Browse files
authored
Font subset (#14828)
1 parent 41e2fa3 commit abaac56

File tree

12 files changed

+312
-1
lines changed

12 files changed

+312
-1
lines changed

BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ group("flutter") {
3131
"$flutter_root/sky",
3232
]
3333

34+
if (current_toolchain == host_toolchain) {
35+
public_deps += [ "$flutter_root/tools/font-subset" ]
36+
}
37+
3438
if (current_toolchain == host_toolchain) {
3539
public_deps += [ "$flutter_root/shell/testing" ]
3640
}

testing/run_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
fonts_dir = os.path.join(buildroot_dir, 'flutter', 'third_party', 'txt', 'third_party', 'fonts')
2121
roboto_font_path = os.path.join(fonts_dir, 'Roboto-Regular.ttf')
2222
dart_tests_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'dart',)
23+
font_subset_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'font-subset')
2324

2425
fml_unittests_filter = '--gtest_filter=-*TimeSensitiveTest*:*GpuThreadMerger*'
2526

@@ -326,7 +327,7 @@ def main():
326327
args = parser.parse_args()
327328

328329
if args.type == 'all':
329-
types = ['engine', 'dart', 'benchmarks', 'java']
330+
types = ['engine', 'dart', 'benchmarks', 'java', 'font-subset']
330331
else:
331332
types = args.type.split(',')
332333

@@ -355,6 +356,9 @@ def main():
355356
if 'benchmarks' in types and not IsWindows():
356357
RunEngineBenchmarks(build_dir, engine_filter)
357358

359+
if 'engine' in types or 'font-subset' in types:
360+
RunCmd(['python', 'test.py'], cwd=font_subset_dir)
361+
358362

359363
if __name__ == '__main__':
360364
sys.exit(main())

tools/font-subset/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gen/*.ttf

tools/font-subset/BUILD.gn

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
executable("font-subset") {
6+
sources = [
7+
"hb_wrappers.h",
8+
"main.cc",
9+
]
10+
11+
deps = [
12+
"//third_party/harfbuzz",
13+
]
14+
15+
libs = []
16+
if (is_mac) {
17+
libs += [
18+
"Foundation.framework",
19+
"CoreGraphics.framework",
20+
"CoreText.framework",
21+
]
22+
}
23+
}

tools/font-subset/fixtures/1.ttf

1.12 KB
Binary file not shown.

tools/font-subset/fixtures/2.ttf

1.22 KB
Binary file not shown.

tools/font-subset/fixtures/3.ttf

1.32 KB
Binary file not shown.
131 KB
Binary file not shown.

tools/font-subset/gen/.gitkeep

Whitespace-only changes.

tools/font-subset/hb_wrappers.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef HB_WRAPPERS_H_
6+
#define HB_WRAPPERS_H_
7+
8+
#include <hb-subset.h>
9+
10+
namespace HarfbuzzWrappers {
11+
struct hb_blob_deleter {
12+
void operator()(hb_blob_t* ptr) { hb_blob_destroy(ptr); }
13+
};
14+
15+
struct hb_face_deleter {
16+
void operator()(hb_face_t* ptr) { hb_face_destroy(ptr); }
17+
};
18+
19+
struct hb_subset_input_deleter {
20+
void operator()(hb_subset_input_t* ptr) { hb_subset_input_destroy(ptr); }
21+
};
22+
23+
struct hb_set_deleter {
24+
void operator()(hb_set_t* ptr) { hb_set_destroy(ptr); }
25+
};
26+
27+
using HbBlobPtr = std::unique_ptr<hb_blob_t, hb_blob_deleter>;
28+
using HbFacePtr = std::unique_ptr<hb_face_t, hb_face_deleter>;
29+
using HbSubsetInputPtr =
30+
std::unique_ptr<hb_subset_input_t, hb_subset_input_deleter>;
31+
using HbSetPtr = std::unique_ptr<hb_set_t, hb_set_deleter>;
32+
33+
}; // namespace HarfbuzzWrappers
34+
35+
#endif // HB_WRAPPERS_H_s

0 commit comments

Comments
 (0)