diff --git a/lib/web_ui/lib/src/engine/canvaskit/fonts.dart b/lib/web_ui/lib/src/engine/canvaskit/fonts.dart index 234d7908b99e6..84475d4f82a28 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/fonts.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/fonts.dart @@ -184,15 +184,12 @@ class SkiaFontCollection implements FontCollection { } } final List completedPendingFonts = await Future.wait(pendingFonts); - final List fonts = [ - UnregisteredFont( + completedPendingFonts.add(UnregisteredFont( EmbeddedTestFont.flutterTest.data.buffer, '', EmbeddedTestFont.flutterTest.fontFamily, - ), - ...completedPendingFonts.whereType(), - ]; - _unregisteredFonts.addAll(fonts); + )); + _unregisteredFonts.addAll(completedPendingFonts.whereType()); // Ahem must be added to font fallbacks list regardless of where it was // downloaded from. diff --git a/lib/web_ui/lib/src/engine/text/font_collection.dart b/lib/web_ui/lib/src/engine/text/font_collection.dart index 3865deb3343ea..7c863d5e87c2e 100644 --- a/lib/web_ui/lib/src/engine/text/font_collection.dart +++ b/lib/web_ui/lib/src/engine/text/font_collection.dart @@ -76,13 +76,13 @@ class HtmlFontCollection implements FontCollection { @override Future debugDownloadTestFonts() async { final FontManager fontManager = _testFontManager = FontManager(); + for (final MapEntry fontEntry in testFontUrls.entries) { + fontManager.downloadAsset(fontEntry.key, 'url(${fontEntry.value})', const {}); + } fontManager._downloadedFonts.add(createDomFontFace( EmbeddedTestFont.flutterTest.fontFamily, EmbeddedTestFont.flutterTest.data, )); - for (final MapEntry fontEntry in testFontUrls.entries) { - fontManager.downloadAsset(fontEntry.key, 'url(${fontEntry.value})', const {}); - } await fontManager.downloadAllFonts(); } diff --git a/lib/web_ui/test/canvaskit/skia_font_collection_test.dart b/lib/web_ui/test/canvaskit/skia_font_collection_test.dart index 75764a8c35f4f..2650e586fa864 100644 --- a/lib/web_ui/test/canvaskit/skia_font_collection_test.dart +++ b/lib/web_ui/test/canvaskit/skia_font_collection_test.dart @@ -181,14 +181,5 @@ void testMain() { expect(fontCollection.debugRegisteredFonts, isNotEmpty); expect(warnings, isEmpty); }); - - test('FlutterTest is the default test font', () async { - final SkiaFontCollection fontCollection = SkiaFontCollection(); - - await fontCollection.debugDownloadTestFonts(); - fontCollection.registerDownloadedFonts(); - expect(fontCollection.debugRegisteredFonts, isNotEmpty); - expect(fontCollection.debugRegisteredFonts!.first.family, 'FlutterTest'); - }); }); } diff --git a/runtime/test_font_data.cc b/runtime/test_font_data.cc index 9389079a8bbd1..9f86698dab1f1 100644 --- a/runtime/test_font_data.cc +++ b/runtime/test_font_data.cc @@ -1621,19 +1621,19 @@ namespace flutter { std::vector> GetTestFontData() { std::vector> typefaces; #if EMBED_TEST_FONT_DATA - typefaces.push_back(SkTypeface::MakeFromStream( - SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength))); typefaces.push_back(SkTypeface::MakeFromStream( SkMemoryStream::MakeDirect(kAhemFont, kAhemFontLength))); typefaces.push_back(SkTypeface::MakeFromStream( SkMemoryStream::MakeDirect(kCoughFont, kCoughFontLength))); + typefaces.push_back(SkTypeface::MakeFromStream( + SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength))); #endif // EMBED_TEST_FONT_DATA return typefaces; } std::vector GetTestFontFamilyNames() { #if EMBED_TEST_FONT_DATA - std::vector names = {"FlutterTest", "Ahem", "Cough"}; + std::vector names = {"Ahem", "Cough", "FlutterTest"}; #else // EMBED_TEST_FONT_DATA std::vector names; #endif // EMBED_TEST_FONT_DATA diff --git a/testing/dart/canvas_test.dart b/testing/dart/canvas_test.dart index 451beaf243af5..c230382017025 100644 --- a/testing/dart/canvas_test.dart +++ b/testing/dart/canvas_test.dart @@ -331,7 +331,6 @@ void main() { builder.pushStyle(TextStyle( decoration: TextDecoration.underline, decorationColor: const Color(0xFF0000FF), - fontFamily: 'Ahem', fontSize: 10, color: const Color(0xFF000000), decorationStyle: style, diff --git a/testing/dart/paragraph_builder_test.dart b/testing/dart/paragraph_builder_test.dart index 14761f17f9c83..37e27a758147a 100644 --- a/testing/dart/paragraph_builder_test.dart +++ b/testing/dart/paragraph_builder_test.dart @@ -7,6 +7,9 @@ import 'dart:ui'; import 'package:litetest/litetest.dart'; void main() { + // The actual values for font measurements will vary by platform slightly. + const double epsillon = 0.0001; + test('Should be able to build and layout a paragraph', () { final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle()); builder.addText('Hello'); @@ -37,10 +40,10 @@ void main() { final List boxes = paragraph.getBoxesForRange(0, 3); expect(boxes.length, 1); - expect(boxes.first.left, 0.0); - expect(boxes.first.top, 0.0); - expect(boxes.first.right, 42.0); - expect(boxes.first.bottom, 14.0); + expect(boxes.first.left, 0); + expect(boxes.first.top, closeTo(0, epsillon)); + expect(boxes.first.right, closeTo(42, epsillon)); + expect(boxes.first.bottom, closeTo(14, epsillon)); expect(boxes.first.direction, TextDirection.ltr); }); @@ -57,13 +60,13 @@ void main() { final List metrics = paragraph.computeLineMetrics(); expect(metrics.length, 1); expect(metrics.first.hardBreak, true); - expect(metrics.first.ascent, 10.5); - expect(metrics.first.descent, 3.5); - expect(metrics.first.unscaledAscent, 10.5); + expect(metrics.first.ascent, closeTo(11.200042724609375, epsillon)); + expect(metrics.first.descent, closeTo(2.799957275390625, epsillon)); + expect(metrics.first.unscaledAscent, closeTo(11.200042724609375, epsillon)); expect(metrics.first.height, 14.0); expect(metrics.first.width, 70.0); expect(metrics.first.left, 0.0); - expect(metrics.first.baseline, 10.5); + expect(metrics.first.baseline, closeTo(11.200042724609375, epsillon)); expect(metrics.first.lineNumber, 0); }); }