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

Commit 9270e3d

Browse files
Make FlutterTest the default test font (#40188)
Make FlutterTest the default test font
1 parent 7572fe5 commit 9270e3d

6 files changed

Lines changed: 30 additions & 20 deletions

File tree

lib/web_ui/lib/src/engine/canvaskit/fonts.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,15 @@ class SkiaFontCollection implements FontCollection {
184184
}
185185
}
186186
final List<UnregisteredFont?> completedPendingFonts = await Future.wait(pendingFonts);
187-
completedPendingFonts.add(UnregisteredFont(
187+
final List<UnregisteredFont> fonts = <UnregisteredFont>[
188+
UnregisteredFont(
188189
EmbeddedTestFont.flutterTest.data.buffer,
189190
'<embedded>',
190191
EmbeddedTestFont.flutterTest.fontFamily,
191-
));
192-
_unregisteredFonts.addAll(completedPendingFonts.whereType<UnregisteredFont>());
192+
),
193+
...completedPendingFonts.whereType<UnregisteredFont>(),
194+
];
195+
_unregisteredFonts.addAll(fonts);
193196

194197
// Ahem must be added to font fallbacks list regardless of where it was
195198
// downloaded from.

lib/web_ui/lib/src/engine/text/font_collection.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ class HtmlFontCollection implements FontCollection {
7676
@override
7777
Future<void> debugDownloadTestFonts() async {
7878
final FontManager fontManager = _testFontManager = FontManager();
79-
for (final MapEntry<String, String> fontEntry in testFontUrls.entries) {
80-
fontManager.downloadAsset(fontEntry.key, 'url(${fontEntry.value})', const <String, String>{});
81-
}
8279
fontManager._downloadedFonts.add(createDomFontFace(
8380
EmbeddedTestFont.flutterTest.fontFamily,
8481
EmbeddedTestFont.flutterTest.data,
8582
));
83+
for (final MapEntry<String, String> fontEntry in testFontUrls.entries) {
84+
fontManager.downloadAsset(fontEntry.key, 'url(${fontEntry.value})', const <String, String>{});
85+
}
8686
await fontManager.downloadAllFonts();
8787
}
8888

lib/web_ui/test/canvaskit/skia_font_collection_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,14 @@ void testMain() {
181181
expect(fontCollection.debugRegisteredFonts, isNotEmpty);
182182
expect(warnings, isEmpty);
183183
});
184+
185+
test('FlutterTest is the default test font', () async {
186+
final SkiaFontCollection fontCollection = SkiaFontCollection();
187+
188+
await fontCollection.debugDownloadTestFonts();
189+
fontCollection.registerDownloadedFonts();
190+
expect(fontCollection.debugRegisteredFonts, isNotEmpty);
191+
expect(fontCollection.debugRegisteredFonts!.first.family, 'FlutterTest');
192+
});
184193
});
185194
}

runtime/test_font_data.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,19 +1621,19 @@ namespace flutter {
16211621
std::vector<sk_sp<SkTypeface>> GetTestFontData() {
16221622
std::vector<sk_sp<SkTypeface>> typefaces;
16231623
#if EMBED_TEST_FONT_DATA
1624+
typefaces.push_back(SkTypeface::MakeFromStream(
1625+
SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength)));
16241626
typefaces.push_back(SkTypeface::MakeFromStream(
16251627
SkMemoryStream::MakeDirect(kAhemFont, kAhemFontLength)));
16261628
typefaces.push_back(SkTypeface::MakeFromStream(
16271629
SkMemoryStream::MakeDirect(kCoughFont, kCoughFontLength)));
1628-
typefaces.push_back(SkTypeface::MakeFromStream(
1629-
SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength)));
16301630
#endif // EMBED_TEST_FONT_DATA
16311631
return typefaces;
16321632
}
16331633

16341634
std::vector<std::string> GetTestFontFamilyNames() {
16351635
#if EMBED_TEST_FONT_DATA
1636-
std::vector<std::string> names = {"Ahem", "Cough", "FlutterTest"};
1636+
std::vector<std::string> names = {"FlutterTest", "Ahem", "Cough"};
16371637
#else // EMBED_TEST_FONT_DATA
16381638
std::vector<std::string> names;
16391639
#endif // EMBED_TEST_FONT_DATA

testing/dart/canvas_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ void main() {
331331
builder.pushStyle(TextStyle(
332332
decoration: TextDecoration.underline,
333333
decorationColor: const Color(0xFF0000FF),
334+
fontFamily: 'Ahem',
334335
fontSize: 10,
335336
color: const Color(0xFF000000),
336337
decorationStyle: style,

testing/dart/paragraph_builder_test.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import 'dart:ui';
77
import 'package:litetest/litetest.dart';
88

99
void main() {
10-
// The actual values for font measurements will vary by platform slightly.
11-
const double epsillon = 0.0001;
12-
1310
test('Should be able to build and layout a paragraph', () {
1411
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle());
1512
builder.addText('Hello');
@@ -40,10 +37,10 @@ void main() {
4037

4138
final List<TextBox> boxes = paragraph.getBoxesForRange(0, 3);
4239
expect(boxes.length, 1);
43-
expect(boxes.first.left, 0);
44-
expect(boxes.first.top, closeTo(0, epsillon));
45-
expect(boxes.first.right, closeTo(42, epsillon));
46-
expect(boxes.first.bottom, closeTo(14, epsillon));
40+
expect(boxes.first.left, 0.0);
41+
expect(boxes.first.top, 0.0);
42+
expect(boxes.first.right, 42.0);
43+
expect(boxes.first.bottom, 14.0);
4744
expect(boxes.first.direction, TextDirection.ltr);
4845
});
4946

@@ -60,13 +57,13 @@ void main() {
6057
final List<LineMetrics> metrics = paragraph.computeLineMetrics();
6158
expect(metrics.length, 1);
6259
expect(metrics.first.hardBreak, true);
63-
expect(metrics.first.ascent, closeTo(11.200042724609375, epsillon));
64-
expect(metrics.first.descent, closeTo(2.799957275390625, epsillon));
65-
expect(metrics.first.unscaledAscent, closeTo(11.200042724609375, epsillon));
60+
expect(metrics.first.ascent, 10.5);
61+
expect(metrics.first.descent, 3.5);
62+
expect(metrics.first.unscaledAscent, 10.5);
6663
expect(metrics.first.height, 14.0);
6764
expect(metrics.first.width, 70.0);
6865
expect(metrics.first.left, 0.0);
69-
expect(metrics.first.baseline, closeTo(11.200042724609375, epsillon));
66+
expect(metrics.first.baseline, 10.5);
7067
expect(metrics.first.lineNumber, 0);
7168
});
7269
}

0 commit comments

Comments
 (0)