[web] Make sure to include all split fonts (flutter/engine#56733)
The `csslib` parser was not reliably parsing all URLs in the CSS response. I'm switching to using a RegExp to extract all URLs reliably. Fixes https://github.com/flutter/flutter/issues/159215
This commit is contained in:
parent
3e281cda44
commit
b56fac41f9
2
DEPS
2
DEPS
@ -925,7 +925,7 @@ deps = {
|
|||||||
'packages': [
|
'packages': [
|
||||||
{
|
{
|
||||||
'package': 'flutter/flutter_font_fallbacks',
|
'package': 'flutter/flutter_font_fallbacks',
|
||||||
'version': '8a753fd2150c398a5777a7fdb24fc9d4d5fe8015088c5237b61cf0ff26653fd0'
|
'version': '44bd38be0bc8c189a397ca6dd6f737746a9e0c6117b96a8f84f1edf6acd1206b'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'dep_type': 'cipd',
|
'dep_type': 'cipd',
|
||||||
|
@ -9,8 +9,6 @@ import 'dart:typed_data';
|
|||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
import 'package:convert/convert.dart';
|
import 'package:convert/convert.dart';
|
||||||
import 'package:crypto/crypto.dart' as crypto;
|
import 'package:crypto/crypto.dart' as crypto;
|
||||||
import 'package:csslib/parser.dart' as csslib;
|
|
||||||
import 'package:csslib/visitor.dart' show StyleSheet, UriTerm, Visitor;
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
@ -346,13 +344,14 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
|
|||||||
'Chrome/112.0.0.0 Safari/537.36'
|
'Chrome/112.0.0.0 Safari/537.36'
|
||||||
});
|
});
|
||||||
final String cssString = response.body;
|
final String cssString = response.body;
|
||||||
final StyleSheet stylesheet = csslib.parse(cssString);
|
// Match the patterns that look like:
|
||||||
final UriCollector uriCollector = UriCollector();
|
// `src: url(...some url...)`
|
||||||
stylesheet.visit(uriCollector);
|
final r = RegExp(r'src:\s*url\((https?://[^)]+?\.woff2)\)');
|
||||||
int familyCount = 0;
|
int familyCount = 0;
|
||||||
// Give each font shard a unique family name.
|
// Give each font shard a unique family name.
|
||||||
for (final Uri uri in uriCollector.uris) {
|
for (final match in r.allMatches(cssString)) {
|
||||||
final String family = '$font $familyCount';
|
final String family = '$font $familyCount';
|
||||||
|
final Uri uri = Uri.parse(match.group(1)!);
|
||||||
processedFonts.add((
|
processedFonts.add((
|
||||||
family: family,
|
family: family,
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@ -364,15 +363,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UriCollector extends Visitor {
|
|
||||||
final List<Uri> uris = <Uri>[];
|
|
||||||
|
|
||||||
@override
|
|
||||||
void visitUriTerm(UriTerm uriTerm) {
|
|
||||||
uris.add(Uri.parse(uriTerm.value as String));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fonts that should be downloaded directly from the Google Fonts API.
|
/// Fonts that should be downloaded directly from the Google Fonts API.
|
||||||
const List<String> apiFallbackFonts = <String>[
|
const List<String> apiFallbackFonts = <String>[
|
||||||
'Noto Sans',
|
'Noto Sans',
|
||||||
|
File diff suppressed because one or more lines are too long
@ -21,7 +21,6 @@ dev_dependencies:
|
|||||||
archive: 3.6.1
|
archive: 3.6.1
|
||||||
args: any
|
args: any
|
||||||
async: any
|
async: any
|
||||||
csslib: 1.0.0
|
|
||||||
convert: any
|
convert: any
|
||||||
crypto: any
|
crypto: any
|
||||||
html: 0.15.4
|
html: 0.15.4
|
||||||
|
@ -384,11 +384,11 @@ void testMain() {
|
|||||||
...[for (int i = 0; i <= 2; i++) 'Noto Sans Cuneiform $i'],
|
...[for (int i = 0; i <= 2; i++) 'Noto Sans Cuneiform $i'],
|
||||||
...[for (int i = 0; i <= 2; i++) 'Noto Sans Duployan $i'],
|
...[for (int i = 0; i <= 2; i++) 'Noto Sans Duployan $i'],
|
||||||
...[for (int i = 0; i <= 2; i++) 'Noto Sans Egyptian Hieroglyphs $i'],
|
...[for (int i = 0; i <= 2; i++) 'Noto Sans Egyptian Hieroglyphs $i'],
|
||||||
...[for (int i = 0; i <= 103; i++) 'Noto Sans HK $i'],
|
...[for (int i = 0; i <= 108; i++) 'Noto Sans HK $i'],
|
||||||
...[for (int i = 0; i <= 123; i++) 'Noto Sans JP $i'],
|
...[for (int i = 0; i <= 123; i++) 'Noto Sans JP $i'],
|
||||||
...[for (int i = 0; i <= 117; i++) 'Noto Sans KR $i'],
|
...[for (int i = 0; i <= 123; i++) 'Noto Sans KR $i'],
|
||||||
...[for (int i = 0; i <= 95; i++) 'Noto Sans SC $i'],
|
...[for (int i = 0; i <= 100; i++) 'Noto Sans SC $i'],
|
||||||
...[for (int i = 0; i <= 99; i++) 'Noto Sans TC $i'],
|
...[for (int i = 0; i <= 104; i++) 'Noto Sans TC $i'],
|
||||||
'Noto Music',
|
'Noto Music',
|
||||||
'Noto Sans',
|
'Noto Sans',
|
||||||
'Noto Sans Symbols',
|
'Noto Sans Symbols',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user