@@ -138,15 +138,15 @@ class IconTreeShaker {
138
138
if (codePoints == null ) {
139
139
throw IconTreeShakerException ._('Expected to font code points for ${entry .key }, but none were found.' );
140
140
}
141
- if (_targetPlatform == TargetPlatform .web_javascript) {
142
- if (! codePoints.contains (kSpacePoint)) {
143
- codePoints.add (kSpacePoint);
144
- }
145
- }
141
+
142
+ // Add space as an optional code point, as web uses it to measure the font height.
143
+ final List <int > optionalCodePoints = _targetPlatform == TargetPlatform .web_javascript
144
+ ? < int > [kSpacePoint] : < int > [];
146
145
result[entry.value] = _IconTreeShakerData (
147
146
family: entry.key,
148
147
relativePath: entry.value,
149
148
codePoints: codePoints,
149
+ optionalCodePoints: optionalCodePoints,
150
150
);
151
151
}
152
152
_iconData = result;
@@ -197,12 +197,17 @@ class IconTreeShaker {
197
197
outputPath,
198
198
input.path,
199
199
];
200
- final String codePoints = iconTreeShakerData.codePoints.join (' ' );
200
+ final Iterable <String > requiredCodePointStrings = iconTreeShakerData.codePoints
201
+ .map ((int codePoint) => codePoint.toString ());
202
+ final Iterable <String > optionalCodePointStrings = iconTreeShakerData.optionalCodePoints
203
+ .map ((int codePoint) => 'optional:$codePoint ' );
204
+ final String codePointsString = requiredCodePointStrings
205
+ .followedBy (optionalCodePointStrings).join (' ' );
201
206
_logger.printTrace ('Running font-subset: ${cmd .join (' ' )}, '
202
- 'using codepoints $codePoints ' );
207
+ 'using codepoints $codePointsString ' );
203
208
final Process fontSubsetProcess = await _processManager.start (cmd);
204
209
try {
205
- fontSubsetProcess.stdin.writeln (codePoints );
210
+ fontSubsetProcess.stdin.writeln (codePointsString );
206
211
await fontSubsetProcess.stdin.flush ();
207
212
await fontSubsetProcess.stdin.close ();
208
213
} on Exception {
@@ -369,6 +374,7 @@ class _IconTreeShakerData {
369
374
required this .family,
370
375
required this .relativePath,
371
376
required this .codePoints,
377
+ required this .optionalCodePoints,
372
378
});
373
379
374
380
/// The font family name, e.g. "MaterialIcons".
@@ -380,6 +386,10 @@ class _IconTreeShakerData {
380
386
/// The list of code points for the font.
381
387
final List <int > codePoints;
382
388
389
+ /// The list of code points to be optionally added, if they exist in the
390
+ /// input font. Otherwise, the tool will silently omit them.
391
+ final List <int > optionalCodePoints;
392
+
383
393
@override
384
394
String toString () => 'FontSubsetData($family , $relativePath , $codePoints )' ;
385
395
}
0 commit comments