未验证 提交 8320617d 编写于 作者: H Harry Terkelsen 提交者: GitHub

Adds Roboto as a global font fallback in CanvasKit (#23928)

上级 82a0b588
...@@ -28,7 +28,7 @@ class SkiaFontCollection { ...@@ -28,7 +28,7 @@ class SkiaFontCollection {
final Map<String, List<SkTypeface>> familyToTypefaceMap = final Map<String, List<SkTypeface>> familyToTypefaceMap =
<String, List<SkTypeface>>{}; <String, List<SkTypeface>>{};
final List<String> globalFontFallbacks = <String>[]; final List<String> globalFontFallbacks = <String>['Roboto'];
final Map<String, int> _fontFallbackCounts = <String, int>{}; final Map<String, int> _fontFallbackCounts = <String, int>{};
...@@ -178,6 +178,7 @@ class SkiaFontCollection { ...@@ -178,6 +178,7 @@ class SkiaFontCollection {
void debugResetFallbackFonts() { void debugResetFallbackFonts() {
_registeredFallbackFonts.clear(); _registeredFallbackFonts.clear();
globalFontFallbacks.clear(); globalFontFallbacks.clear();
globalFontFallbacks.add('Roboto');
_fontFallbackCounts.clear(); _fontFallbackCounts.clear();
} }
......
...@@ -814,9 +814,7 @@ enum _ParagraphCommandType { ...@@ -814,9 +814,7 @@ enum _ParagraphCommandType {
List<String> _getEffectiveFontFamilies(String? fontFamily, List<String> _getEffectiveFontFamilies(String? fontFamily,
[List<String>? fontFamilyFallback]) { [List<String>? fontFamilyFallback]) {
List<String> fontFamilies = <String>[]; List<String> fontFamilies = <String>[];
if (fontFamily == null) { if (fontFamily != null) {
fontFamilies.add('Roboto');
} else {
fontFamilies.add(fontFamily); fontFamilies.add(fontFamily);
} }
if (fontFamilyFallback != null && if (fontFamilyFallback != null &&
......
...@@ -51,6 +51,10 @@ void testMain() { ...@@ -51,6 +51,10 @@ void testMain() {
ui.window.onPlatformMessage = savedCallback; ui.window.onPlatformMessage = savedCallback;
}); });
test('Roboto is always a fallback font', () {
expect(skiaFontCollection.globalFontFallbacks, contains('Roboto'));
});
test('will download Noto Naskh Arabic if Arabic text is added', () async { test('will download Noto Naskh Arabic if Arabic text is added', () async {
final Completer<void> fontChangeCompleter = Completer<void>(); final Completer<void> fontChangeCompleter = Completer<void>();
// Intercept the system font change message. // Intercept the system font change message.
...@@ -83,7 +87,7 @@ void testMain() { ...@@ -83,7 +87,7 @@ void testMain() {
} }
'''; ''';
expect(skiaFontCollection.globalFontFallbacks, isEmpty); expect(skiaFontCollection.globalFontFallbacks, ['Roboto']);
// Creating this paragraph should cause us to start to download the // Creating this paragraph should cause us to start to download the
// fallback font. // fallback font.
...@@ -123,7 +127,7 @@ void testMain() { ...@@ -123,7 +127,7 @@ void testMain() {
'https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic+UI'] = 'https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic+UI'] =
'invalid CSS... this should cause our parser to fail'; 'invalid CSS... this should cause our parser to fail';
expect(skiaFontCollection.globalFontFallbacks, isEmpty); expect(skiaFontCollection.globalFontFallbacks, ['Roboto']);
// Creating this paragraph should cause us to start to download the // Creating this paragraph should cause us to start to download the
// fallback font. // fallback font.
...@@ -136,7 +140,7 @@ void testMain() { ...@@ -136,7 +140,7 @@ void testMain() {
await Future<void>.delayed(Duration.zero); await Future<void>.delayed(Duration.zero);
expect(notoDownloadQueue.isPending, isFalse); expect(notoDownloadQueue.isPending, isFalse);
expect(skiaFontCollection.globalFontFallbacks, isEmpty); expect(skiaFontCollection.globalFontFallbacks, ['Roboto']);
}); });
// TODO: https://github.com/flutter/flutter/issues/60040 // TODO: https://github.com/flutter/flutter/issues/60040
}, skip: isIosSafari); }, skip: isIosSafari);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册