@@ -24,24 +24,24 @@ class FontFallbackManager {
24
24
factory FontFallbackManager (FallbackFontRegistry registry) =>
25
25
FontFallbackManager ._(registry, getFallbackFontList ());
26
26
27
- FontFallbackManager ._(this .registry , this .fallbackFonts )
28
- : _notoSymbols = fallbackFonts .singleWhere (
27
+ FontFallbackManager ._(this ._registry , this ._fallbackFonts )
28
+ : _notoSymbols = _fallbackFonts .singleWhere (
29
29
(NotoFont font) => font.name == 'Noto Sans Symbols' ,
30
30
) {
31
- downloadQueue = FallbackFontDownloadQueue (this );
31
+ _downloadQueue = _FallbackFontDownloadQueue (this );
32
32
}
33
33
34
- final FallbackFontRegistry registry ;
34
+ final FallbackFontRegistry _registry ;
35
35
36
- late final FallbackFontDownloadQueue downloadQueue ;
36
+ late final _FallbackFontDownloadQueue _downloadQueue ;
37
37
38
38
/// Code points that no known font has a glyph for.
39
- final Set <int > codePointsWithNoKnownFont = < int > {};
39
+ final Set <int > _codePointsWithNoKnownFont = < int > {};
40
40
41
41
/// Code points which are known to be covered by at least one fallback font.
42
- final Set <int > knownCoveredCodePoints = < int > {};
42
+ final Set <int > _knownCoveredCodePoints = < int > {};
43
43
44
- final List <NotoFont > fallbackFonts ;
44
+ final List <NotoFont > _fallbackFonts ;
45
45
46
46
// By default, we use the system language to determine the user's preferred
47
47
// language. This can be overridden through [debugUserPreferredLanguage] for testing.
@@ -55,6 +55,9 @@ class FontFallbackManager {
55
55
_language = value;
56
56
}
57
57
58
+ @visibleForTesting
59
+ void Function (String family)? debugOnLoadFontFamily;
60
+
58
61
final NotoFont _notoSymbols;
59
62
60
63
Future <void > _idleFuture = Future <void >.value ();
@@ -101,8 +104,8 @@ class FontFallbackManager {
101
104
for (final int rune in text.runes) {
102
105
// Filter out code points that don't need checking.
103
106
if (! (rune < 160 || // ASCII and Unicode control points.
104
- knownCoveredCodePoints .contains (rune) || // Points we've already covered
105
- codePointsWithNoKnownFont .contains (rune)) // Points that don't have a fallback font
107
+ _knownCoveredCodePoints .contains (rune) || // Points we've already covered
108
+ _codePointsWithNoKnownFont .contains (rune)) // Points that don't have a fallback font
106
109
) {
107
110
runesToCheck.add (rune);
108
111
}
@@ -112,7 +115,7 @@ class FontFallbackManager {
112
115
}
113
116
114
117
final List <int > codePoints = runesToCheck.toList ();
115
- final List <int > missingCodePoints = registry .getMissingCodePoints (codePoints, fontFamilies);
118
+ final List <int > missingCodePoints = _registry .getMissingCodePoints (codePoints, fontFamilies);
116
119
117
120
if (missingCodePoints.isNotEmpty) {
118
121
addMissingCodePoints (codePoints);
@@ -126,7 +129,7 @@ class FontFallbackManager {
126
129
_idleFuture = Future <void >.delayed (Duration .zero, () async {
127
130
_ensureFallbackFonts ();
128
131
_scheduledCodePointCheck = false ;
129
- await downloadQueue .waitForIdle ();
132
+ await _downloadQueue .waitForIdle ();
130
133
});
131
134
}
132
135
}
@@ -168,7 +171,7 @@ class FontFallbackManager {
168
171
/// user's locale.
169
172
///
170
173
/// If a code point is not covered by any font, it is added to
171
- /// [codePointsWithNoKnownFont ] so it can be omitted next time to avoid
174
+ /// [_codePointsWithNoKnownFont ] so it can be omitted next time to avoid
172
175
/// searching for fonts unnecessarily.
173
176
void findFontsForMissingCodePoints (List <int > codePoints) {
174
177
final List <int > missingCodePoints = < int > [];
@@ -227,18 +230,18 @@ class FontFallbackManager {
227
230
candidateFonts.removeWhere ((NotoFont font) => font.coverCount == 0 );
228
231
}
229
232
230
- selectedFonts.forEach (downloadQueue .add);
233
+ selectedFonts.forEach (_downloadQueue .add);
231
234
232
235
// Report code points not covered by any fallback font and ensure we don't
233
236
// process those code points again.
234
237
if (missingCodePoints.isNotEmpty) {
235
- if (! downloadQueue .isPending) {
238
+ if (! _downloadQueue .isPending) {
236
239
printWarning (
237
240
'Could not find a set of Noto fonts to display all missing '
238
241
'characters. Please add a font asset for the missing characters.'
239
242
' See: https://flutter.dev/docs/cookbook/design/fonts' ,
240
243
);
241
- codePointsWithNoKnownFont .addAll (missingCodePoints);
244
+ _codePointsWithNoKnownFont .addAll (missingCodePoints);
242
245
}
243
246
}
244
247
}
@@ -335,7 +338,7 @@ class FontFallbackManager {
335
338
if (kFontIndexDigit0 <= code && code < kFontIndexDigit0 + kFontIndexRadix) {
336
339
final int delta = prefix * kFontIndexRadix + (code - kFontIndexDigit0);
337
340
final int index = previousIndex + delta + 1 ;
338
- result.add (fallbackFonts [index]);
341
+ result.add (_fallbackFonts [index]);
339
342
previousIndex = index;
340
343
prefix = 0 ;
341
344
} else if (kPrefixDigit0 <= code && code < kPrefixDigit0 + kPrefixRadix) {
@@ -436,20 +439,16 @@ class _UnicodePropertyLookup<P> {
436
439
}
437
440
}
438
441
439
- class FallbackFontDownloadQueue {
440
- FallbackFontDownloadQueue (this .fallbackManager);
442
+ class _FallbackFontDownloadQueue {
443
+ _FallbackFontDownloadQueue (this .fallbackManager);
441
444
442
445
final FontFallbackManager fallbackManager;
443
446
444
- String get fallbackFontUrlPrefix => configuration.fontFallbackBaseUrl;
445
-
446
447
final Set <NotoFont > downloadedFonts = < NotoFont > {};
447
448
final Map <String , NotoFont > pendingFonts = < String , NotoFont > {};
448
449
449
450
bool get isPending => pendingFonts.isNotEmpty;
450
451
451
- void Function (String family)? debugOnLoadFontFamily;
452
-
453
452
Completer <void >? _idleCompleter;
454
453
455
454
Future <void > waitForIdle () {
@@ -478,17 +477,14 @@ class FallbackFontDownloadQueue {
478
477
final List <String > downloadedFontFamilies = < String > [];
479
478
for (final NotoFont font in pendingFonts.values) {
480
479
downloads[font.url] = Future <void >(() async {
480
+ final String url = '${configuration .fontFallbackBaseUrl }${font .url }' ;
481
481
try {
482
- final String url = '$fallbackFontUrlPrefix ${font .url }' ;
483
- debugOnLoadFontFamily? .call (font.name);
484
- await fallbackManager.registry.loadFallbackFont (font.name, url);
482
+ fallbackManager.debugOnLoadFontFamily? .call (font.name);
483
+ await fallbackManager._registry.loadFallbackFont (font.name, url);
485
484
downloadedFontFamilies.add (font.url);
486
485
} catch (e) {
487
486
pendingFonts.remove (font.url);
488
- printWarning (
489
- 'Failed to load font ${font .name } at '
490
- '$fallbackFontUrlPrefix ${font .url }' ,
491
- );
487
+ printWarning ('Failed to load font ${font .name } at $url ' );
492
488
printWarning (e.toString ());
493
489
return ;
494
490
}
@@ -508,7 +504,7 @@ class FallbackFontDownloadQueue {
508
504
}
509
505
510
506
if (pendingFonts.isEmpty) {
511
- fallbackManager.registry .updateFallbackFontFamilies (fallbackManager.globalFontFallbacks);
507
+ fallbackManager._registry .updateFallbackFontFamilies (fallbackManager.globalFontFallbacks);
512
508
sendFontChangeMessage ();
513
509
final Completer <void > idleCompleter = _idleCompleter! ;
514
510
_idleCompleter = null ;
0 commit comments