Skip to content

Commit 1da070c

Browse files
Fix default test font on web (flutter#40479)
Fix default test font on web
1 parent 5cc22b4 commit 1da070c

10 files changed

Lines changed: 29 additions & 26 deletions

File tree

‎lib/web_ui/lib/src/engine/canvaskit/text.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'skia_object_cache.dart';
1616
import 'text_fragmenter.dart';
1717
import 'util.dart';
1818

19-
final List<String> _testFonts = <String>['Ahem', 'FlutterTest'];
19+
final List<String> _testFonts = <String>['FlutterTest', 'Ahem'];
2020
String? _effectiveFontFamily(String? fontFamily) {
2121
return ui.debugEmulateFlutterTesterEnvironment && !_testFonts.contains(fontFamily)
2222
? _testFonts.first

‎lib/web_ui/lib/src/engine/text/paragraph.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class EngineTextStyle implements ui.TextStyle {
464464
final ui.Paint? foreground;
465465
final List<ui.Shadow>? shadows;
466466

467-
static final List<String> _testFonts = <String>['Ahem', 'FlutterTest'];
467+
static final List<String> _testFonts = <String>['FlutterTest', 'Ahem'];
468468
String get effectiveFontFamily {
469469
final String fontFamily = this.fontFamily.isEmpty ? FlutterViewEmbedder.defaultFontFamily : this.fontFamily;
470470
// In the flutter tester environment, we use predictable-size test fonts.

‎lib/web_ui/lib/src/engine/text/ruler.dart‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ class TextDimensions {
119119
..fontFamily = canonicalizeFontFamily(fontFamily)!;
120120

121121
final double? height = textHeightStyle.height;
122-
if (height != null) {
123-
style.lineHeight = height.toString();
122+
// Workaround the rounding introduced by https://github.com/flutter/flutter/issues/122066
123+
// in tests.
124+
final double? effectiveLineHeight = height ?? (fontFamily == 'FlutterTest' ? 1.0 : null);
125+
if (effectiveLineHeight != null) {
126+
style.lineHeight = effectiveLineHeight.toString();
124127
}
125128
_invalidateBoundsCache();
126129
}

‎lib/web_ui/test/canvaskit/flutter_tester_emulation_golden_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void testMain() {
2121
group('flutter_tester emulation', () {
2222
setUpCanvasKitTest();
2323

24-
test('defaults to Ahem font family',
24+
test('defaults to FlutterTest font family',
2525
() async {
2626
final CkPictureRecorder recorder = CkPictureRecorder();
2727
final CkCanvas canvas = recorder.beginRecording(kDefaultRegion);

‎lib/web_ui/test/canvaskit/text_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void testMain() {
9797
final bool resetValue = ui.debugEmulateFlutterTesterEnvironment;
9898
ui.debugEmulateFlutterTesterEnvironment = true;
9999
tearDownAll(() => ui.debugEmulateFlutterTesterEnvironment = resetValue);
100-
const List<String> testFonts = <String>['Ahem', 'FlutterTest'];
100+
const List<String> testFonts = <String>['FlutterTest', 'Ahem'];
101101

102102
test('The default test font is used when a non-test fontFamily is specified', () {
103103
final String defaultTestFontFamily = testFonts.first;

‎lib/web_ui/test/html/paragraph/helper.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const Color yellow = Color(0xFFFFEB3B);
3737
const Color lightPurple = Color(0xFFE1BEE7);
3838

3939
final EngineParagraphStyle ahemStyle = EngineParagraphStyle(
40-
fontFamily: 'ahem',
40+
fontFamily: 'Ahem',
4141
fontSize: 10,
4242
);
4343

‎lib/web_ui/test/text/canvas_paragraph_builder_test.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ Future<void> testMain() async {
410410
});
411411

412412
test('various font sizes', () {
413-
// Paragraphs and spans force the Ahem font in test mode. We need to trick
414-
// them into thinking they are not in test mode, so they use the provided
415-
// font family.
413+
// Paragraphs and spans force the FlutterTest font in test mode. We need to
414+
// trick them into thinking they are not in test mode, so they use the
415+
// provided font family.
416416
debugEmulateFlutterTesterEnvironment = false;
417417
final EngineParagraphStyle style = EngineParagraphStyle(fontSize: 12.0, fontFamily: 'first');
418418
final CanvasParagraphBuilder builder = CanvasParagraphBuilder(style);
@@ -491,7 +491,7 @@ Future<void> testMain() async {
491491
});
492492
}
493493

494-
const String defaultFontFamily = 'Ahem';
494+
const String defaultFontFamily = 'FlutterTest';
495495
const num defaultFontSize = 14;
496496

497497
String paragraphStyle() {

‎lib/web_ui/test/text/layout_service_plain_test.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ Future<void> testMain() async {
388388

389389
test('respects text overflow', () {
390390
final EngineParagraphStyle overflowStyle = EngineParagraphStyle(
391-
fontFamily: 'ahem',
391+
fontFamily: 'Ahem',
392392
fontSize: 10,
393393
ellipsis: '...',
394394
);
@@ -458,7 +458,7 @@ Future<void> testMain() async {
458458

459459
test('respects max lines', () {
460460
final EngineParagraphStyle maxlinesStyle = EngineParagraphStyle(
461-
fontFamily: 'ahem',
461+
fontFamily: 'Ahem',
462462
fontSize: 10,
463463
maxLines: 2,
464464
);
@@ -506,13 +506,13 @@ Future<void> testMain() async {
506506

507507
test('respects text overflow and max lines combined', () {
508508
final EngineParagraphStyle onelineStyle = EngineParagraphStyle(
509-
fontFamily: 'ahem',
509+
fontFamily: 'Ahem',
510510
fontSize: 10,
511511
maxLines: 1,
512512
ellipsis: '...',
513513
);
514514
final EngineParagraphStyle multilineStyle = EngineParagraphStyle(
515-
fontFamily: 'ahem',
515+
fontFamily: 'Ahem',
516516
fontSize: 10,
517517
maxLines: 2,
518518
ellipsis: '...',
@@ -591,7 +591,7 @@ Future<void> testMain() async {
591591

592592
EngineParagraphStyle createStyle(ui.TextAlign textAlign) {
593593
return EngineParagraphStyle(
594-
fontFamily: 'ahem',
594+
fontFamily: 'Ahem',
595595
fontSize: 10,
596596
textAlign: textAlign,
597597
textDirection: ui.TextDirection.ltr,
@@ -644,7 +644,7 @@ Future<void> testMain() async {
644644

645645
EngineParagraphStyle createStyle(ui.TextAlign textAlign) {
646646
return EngineParagraphStyle(
647-
fontFamily: 'ahem',
647+
fontFamily: 'Ahem',
648648
fontSize: 10,
649649
textAlign: textAlign,
650650
textDirection: ui.TextDirection.rtl,

‎lib/web_ui/test/text/layout_service_rich_test.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Future<void> testMain() async {
143143

144144
test('should handle placeholder-only paragraphs', () {
145145
final EngineParagraphStyle paragraphStyle = EngineParagraphStyle(
146-
fontFamily: 'ahem',
146+
fontFamily: 'Ahem',
147147
fontSize: 10,
148148
textAlign: ui.TextAlign.center,
149149
);
@@ -161,7 +161,7 @@ Future<void> testMain() async {
161161

162162
test('correct maxIntrinsicWidth when paragraph ends with placeholder', () {
163163
final EngineParagraphStyle paragraphStyle = EngineParagraphStyle(
164-
fontFamily: 'ahem',
164+
fontFamily: 'Ahem',
165165
fontSize: 10,
166166
textAlign: ui.TextAlign.center,
167167
);
@@ -180,7 +180,7 @@ Future<void> testMain() async {
180180

181181
test('handles new line followed by a placeholder', () {
182182
final EngineParagraphStyle paragraphStyle = EngineParagraphStyle(
183-
fontFamily: 'ahem',
183+
fontFamily: 'Ahem',
184184
fontSize: 10,
185185
textAlign: ui.TextAlign.center,
186186
);

‎lib/web_ui/test/text_test.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ Future<void> testMain() async {
227227
expect(paragraph.plainText, 'abcdef');
228228
final List<DomElement> spans =
229229
paragraph.toDomElement().querySelectorAll('flt-span').toList();
230-
expect(spans[0].style.fontFamily, 'Ahem, $fallback, sans-serif');
230+
expect(spans[0].style.fontFamily, 'FlutterTest, $fallback, sans-serif');
231231
// The nested span here should not set it's family to default sans-serif.
232-
expect(spans[1].style.fontFamily, 'Ahem, $fallback, sans-serif');
232+
expect(spans[1].style.fontFamily, 'FlutterTest, $fallback, sans-serif');
233233
},
234234
// TODO(mdebbar): https://github.com/flutter/flutter/issues/46638
235235
skip: browserEngine == BrowserEngine.firefox);
236236

237237
test('adds Arial and sans-serif as fallback fonts', () {
238-
// Set this to false so it doesn't default to 'Ahem' font.
238+
// Set this to false so it doesn't default to the test font.
239239
debugEmulateFlutterTesterEnvironment = false;
240240

241241
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
@@ -253,7 +253,7 @@ Future<void> testMain() async {
253253
skip: browserEngine == BrowserEngine.firefox);
254254

255255
test('does not add fallback fonts to generic families', () {
256-
// Set this to false so it doesn't default to 'Ahem' font.
256+
// Set this to false so it doesn't default to the default test font.
257257
debugEmulateFlutterTesterEnvironment = false;
258258

259259
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
@@ -268,7 +268,7 @@ Future<void> testMain() async {
268268
});
269269

270270
test('can set font families that need to be quoted', () {
271-
// Set this to false so it doesn't default to 'Ahem' font.
271+
// Set this to false so it doesn't default to the default test font.
272272
debugEmulateFlutterTesterEnvironment = false;
273273

274274
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
@@ -363,7 +363,7 @@ Future<void> testMain() async {
363363
final bool resetValue = debugEmulateFlutterTesterEnvironment;
364364
debugEmulateFlutterTesterEnvironment = true;
365365
tearDownAll(() => debugEmulateFlutterTesterEnvironment = resetValue);
366-
const List<String> testFonts = <String>['Ahem', 'FlutterTest'];
366+
const List<String> testFonts = <String>['FlutterTest', 'Ahem'];
367367

368368
test('The default test font is used when a non-test fontFamily is specified, or fontFamily is not specified', () {
369369
final String defaultTestFontFamily = testFonts.first;

0 commit comments

Comments
 (0)