Unverified Commit 6f227c07 authored by Jackson Gardner's avatar Jackson Gardner Committed by GitHub

Space character should be optional when tree shaking fonts (#132880)

Addresses the other part of https://github.com/flutter/flutter/issues/132711
parent 6d757046
...@@ -138,15 +138,15 @@ class IconTreeShaker { ...@@ -138,15 +138,15 @@ class IconTreeShaker {
if (codePoints == null) { if (codePoints == null) {
throw IconTreeShakerException._('Expected to font code points for ${entry.key}, but none were found.'); throw IconTreeShakerException._('Expected to font code points for ${entry.key}, but none were found.');
} }
if (_targetPlatform == TargetPlatform.web_javascript) {
if (!codePoints.contains(kSpacePoint)) { // Add space as an optional code point, as web uses it to measure the font height.
codePoints.add(kSpacePoint); final List<int> optionalCodePoints = _targetPlatform == TargetPlatform.web_javascript
} ? <int>[kSpacePoint] : <int>[];
}
result[entry.value] = _IconTreeShakerData( result[entry.value] = _IconTreeShakerData(
family: entry.key, family: entry.key,
relativePath: entry.value, relativePath: entry.value,
codePoints: codePoints, codePoints: codePoints,
optionalCodePoints: optionalCodePoints,
); );
} }
_iconData = result; _iconData = result;
...@@ -197,12 +197,17 @@ class IconTreeShaker { ...@@ -197,12 +197,17 @@ class IconTreeShaker {
outputPath, outputPath,
input.path, input.path,
]; ];
final String codePoints = iconTreeShakerData.codePoints.join(' '); final Iterable<String> requiredCodePointStrings = iconTreeShakerData.codePoints
.map((int codePoint) => codePoint.toString());
final Iterable<String> optionalCodePointStrings = iconTreeShakerData.optionalCodePoints
.map((int codePoint) => 'optional:$codePoint');
final String codePointsString = requiredCodePointStrings
.followedBy(optionalCodePointStrings).join(' ');
_logger.printTrace('Running font-subset: ${cmd.join(' ')}, ' _logger.printTrace('Running font-subset: ${cmd.join(' ')}, '
'using codepoints $codePoints'); 'using codepoints $codePointsString');
final Process fontSubsetProcess = await _processManager.start(cmd); final Process fontSubsetProcess = await _processManager.start(cmd);
try { try {
fontSubsetProcess.stdin.writeln(codePoints); fontSubsetProcess.stdin.writeln(codePointsString);
await fontSubsetProcess.stdin.flush(); await fontSubsetProcess.stdin.flush();
await fontSubsetProcess.stdin.close(); await fontSubsetProcess.stdin.close();
} on Exception { } on Exception {
...@@ -369,6 +374,7 @@ class _IconTreeShakerData { ...@@ -369,6 +374,7 @@ class _IconTreeShakerData {
required this.family, required this.family,
required this.relativePath, required this.relativePath,
required this.codePoints, required this.codePoints,
required this.optionalCodePoints,
}); });
/// The font family name, e.g. "MaterialIcons". /// The font family name, e.g. "MaterialIcons".
...@@ -380,6 +386,10 @@ class _IconTreeShakerData { ...@@ -380,6 +386,10 @@ class _IconTreeShakerData {
/// The list of code points for the font. /// The list of code points for the font.
final List<int> codePoints; final List<int> codePoints;
/// The list of code points to be optionally added, if they exist in the
/// input font. Otherwise, the tool will silently omit them.
final List<int> optionalCodePoints;
@override @override
String toString() => 'FontSubsetData($family, $relativePath, $codePoints)'; String toString() => 'FontSubsetData($family, $relativePath, $codePoints)';
} }
......
...@@ -411,7 +411,7 @@ void main() { ...@@ -411,7 +411,7 @@ void main() {
expect(result, isTrue); expect(result, isTrue);
final List<String> codePoints = stdinSink.getAndClear().trim().split(whitespace); final List<String> codePoints = stdinSink.getAndClear().trim().split(whitespace);
expect(codePoints, isNot(contains('32'))); expect(codePoints, isNot(contains('optional:32')));
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}); });
...@@ -456,7 +456,7 @@ void main() { ...@@ -456,7 +456,7 @@ void main() {
expect(result, isTrue); expect(result, isTrue);
final List<String> codePoints = stdinSink.getAndClear().trim().split(whitespace); final List<String> codePoints = stdinSink.getAndClear().trim().split(whitespace);
expect(codePoints, containsAllInOrder(const <String>['59470', '32'])); expect(codePoints, containsAllInOrder(const <String>['59470', 'optional:32']));
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment