forked from firka/flutter
Reland "Make FlutterTest the default test font" (#40188) (flutter/engine#40245)
Reland "Make FlutterTest the default test font" (#40188)
This commit is contained in:
@@ -184,12 +184,15 @@ class SkiaFontCollection implements FontCollection {
|
||||
}
|
||||
}
|
||||
final List<UnregisteredFont?> completedPendingFonts = await Future.wait(pendingFonts);
|
||||
completedPendingFonts.add(UnregisteredFont(
|
||||
final List<UnregisteredFont> fonts = <UnregisteredFont>[
|
||||
UnregisteredFont(
|
||||
EmbeddedTestFont.flutterTest.data.buffer,
|
||||
'<embedded>',
|
||||
EmbeddedTestFont.flutterTest.fontFamily,
|
||||
));
|
||||
_unregisteredFonts.addAll(completedPendingFonts.whereType<UnregisteredFont>());
|
||||
),
|
||||
...completedPendingFonts.whereType<UnregisteredFont>(),
|
||||
];
|
||||
_unregisteredFonts.addAll(fonts);
|
||||
|
||||
// Ahem must be added to font fallbacks list regardless of where it was
|
||||
// downloaded from.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -181,5 +181,14 @@ 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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1621,23 +1621,36 @@ 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(kAhemFont, kAhemFontLength)));
|
||||
const bool defaultsToAhem =
|
||||
std::getenv("FLUTTER_ROOT") && !std::getenv("USE_FLUTTER_TEST_FONT");
|
||||
if (defaultsToAhem) {
|
||||
typefaces.push_back(SkTypeface::MakeFromStream(
|
||||
SkMemoryStream::MakeDirect(kAhemFont, kAhemFontLength)));
|
||||
typefaces.push_back(SkTypeface::MakeFromStream(
|
||||
SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength)));
|
||||
} else {
|
||||
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 = {"Ahem", "Cough", "FlutterTest"};
|
||||
#else // EMBED_TEST_FONT_DATA
|
||||
std::vector<std::string> names;
|
||||
#if EMBED_TEST_FONT_DATA
|
||||
const bool defaultsToAhem =
|
||||
std::getenv("FLUTTER_ROOT") && !std::getenv("USE_FLUTTER_TEST_FONT");
|
||||
if (defaultsToAhem) {
|
||||
names = {"Ahem", "FlutterTest", "Cough"};
|
||||
} else {
|
||||
names = {"FlutterTest", "Ahem", "Cough"};
|
||||
}
|
||||
#endif // EMBED_TEST_FONT_DATA
|
||||
return names;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -331,6 +331,7 @@ void main() {
|
||||
builder.pushStyle(TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: const Color(0xFF0000FF),
|
||||
fontFamily: 'Ahem',
|
||||
fontSize: 10,
|
||||
color: const Color(0xFF000000),
|
||||
decorationStyle: style,
|
||||
|
||||
@@ -7,9 +7,6 @@ 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');
|
||||
@@ -40,10 +37,10 @@ void main() {
|
||||
|
||||
final List<TextBox> boxes = paragraph.getBoxesForRange(0, 3);
|
||||
expect(boxes.length, 1);
|
||||
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.left, 0.0);
|
||||
expect(boxes.first.top, 0.0);
|
||||
expect(boxes.first.right, 42.0);
|
||||
expect(boxes.first.bottom, 14.0);
|
||||
expect(boxes.first.direction, TextDirection.ltr);
|
||||
});
|
||||
|
||||
@@ -60,13 +57,13 @@ void main() {
|
||||
final List<LineMetrics> metrics = paragraph.computeLineMetrics();
|
||||
expect(metrics.length, 1);
|
||||
expect(metrics.first.hardBreak, true);
|
||||
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.ascent, 10.5);
|
||||
expect(metrics.first.descent, 3.5);
|
||||
expect(metrics.first.unscaledAscent, 10.5);
|
||||
expect(metrics.first.height, 14.0);
|
||||
expect(metrics.first.width, 70.0);
|
||||
expect(metrics.first.left, 0.0);
|
||||
expect(metrics.first.baseline, closeTo(11.200042724609375, epsillon));
|
||||
expect(metrics.first.baseline, 10.5);
|
||||
expect(metrics.first.lineNumber, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user