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

Revert "Make FlutterTest the default test font" #40237

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/web_ui/lib/src/engine/canvaskit/fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,12 @@ class SkiaFontCollection implements FontCollection {
}
}
final List<UnregisteredFont?> completedPendingFonts = await Future.wait(pendingFonts);
final List<UnregisteredFont> fonts = <UnregisteredFont>[
UnregisteredFont(
completedPendingFonts.add(UnregisteredFont(
EmbeddedTestFont.flutterTest.data.buffer,
'<embedded>',
EmbeddedTestFont.flutterTest.fontFamily,
),
...completedPendingFonts.whereType<UnregisteredFont>(),
];
_unregisteredFonts.addAll(fonts);
));
_unregisteredFonts.addAll(completedPendingFonts.whereType<UnregisteredFont>());

// Ahem must be added to font fallbacks list regardless of where it was
// downloaded from.
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/text/font_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ class HtmlFontCollection implements FontCollection {
@override
Future<void> debugDownloadTestFonts() async {
final FontManager fontManager = _testFontManager = FontManager();
for (final MapEntry<String, String> fontEntry in testFontUrls.entries) {
fontManager.downloadAsset(fontEntry.key, 'url(${fontEntry.value})', const <String, String>{});
}
fontManager._downloadedFonts.add(createDomFontFace(
EmbeddedTestFont.flutterTest.fontFamily,
EmbeddedTestFont.flutterTest.data,
));
for (final MapEntry<String, String> fontEntry in testFontUrls.entries) {
fontManager.downloadAsset(fontEntry.key, 'url(${fontEntry.value})', const <String, String>{});
}
await fontManager.downloadAllFonts();
}

Expand Down
9 changes: 0 additions & 9 deletions lib/web_ui/test/canvaskit/skia_font_collection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
}
6 changes: 3 additions & 3 deletions runtime/test_font_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1621,19 +1621,19 @@ namespace flutter {
std::vector<sk_sp<SkTypeface>> GetTestFontData() {
std::vector<sk_sp<SkTypeface>> 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<std::string> GetTestFontFamilyNames() {
#if EMBED_TEST_FONT_DATA
std::vector<std::string> names = {"FlutterTest", "Ahem", "Cough"};
std::vector<std::string> names = {"Ahem", "Cough", "FlutterTest"};
#else // EMBED_TEST_FONT_DATA
std::vector<std::string> names;
#endif // EMBED_TEST_FONT_DATA
Expand Down
1 change: 0 additions & 1 deletion testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 11 additions & 8 deletions testing/dart/paragraph_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -37,10 +40,10 @@ void main() {

final List<TextBox> 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);
});

Expand All @@ -57,13 +60,13 @@ void main() {
final List<LineMetrics> 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);
});
}