@@ -450,7 +450,10 @@ class _Elements {
450
450
parserState.currentGroup? .transform,
451
451
),
452
452
);
453
- nextPath.fillType = parserState.parseFillRule ('clip-rule' )! ;
453
+ nextPath.fillType = parserState.parseFillRule (
454
+ 'clip-rule' ,
455
+ 'nonzero' ,
456
+ )! ;
454
457
if (currentPath != null &&
455
458
nextPath.fillType != currentPath.fillType) {
456
459
currentPath = nextPath;
@@ -481,18 +484,6 @@ class _Elements {
481
484
if (warningsAsErrors) {
482
485
throw UnsupportedError (errorMessage);
483
486
}
484
- // FlutterError.reportError(FlutterErrorDetails(
485
- // exception: UnsupportedError(errorMessage),
486
- // informationCollector: () => <DiagnosticsNode>[
487
- // ErrorDescription(
488
- // 'The <clipPath> element contained an unsupported child ${event.name}'),
489
- // if (parserState._key != null) ErrorDescription(''),
490
- // if (parserState._key != null)
491
- // DiagnosticsProperty<String>('Picture key', parserState._key),
492
- // ],
493
- // library: 'SVG',
494
- // context: ErrorDescription('in _Element.clipPath'),
495
- // ));
496
487
}
497
488
}
498
489
}
@@ -938,6 +929,10 @@ class SvgParser {
938
929
currentColor: parent.color,
939
930
leaf: true ,
940
931
);
932
+ if (paint.isEmpty) {
933
+ // This shape does not draw anything. Treat the element as handled.
934
+ return true ;
935
+ }
941
936
final PathNode drawable = PathNode (
942
937
path,
943
938
id: getAttribute (attributes, 'id' ),
@@ -1201,9 +1196,9 @@ class SvgParser {
1201
1196
Rect bounds, {
1202
1197
double ? opacity,
1203
1198
}) {
1204
- final Shader ? shader = definitions.getShader (iri);
1199
+ final Shader ? shader = definitions.getGradient < Shader > (iri);
1205
1200
if (shader == null ) {
1206
- // reportMissingDef (key, iri, '_getDefinitionPaint');
1201
+ _reportMissingDef (key, iri, '_getDefinitionPaint' );
1207
1202
}
1208
1203
1209
1204
switch (paintingStyle) {
@@ -1265,7 +1260,6 @@ class SvgParser {
1265
1260
Rect bounds,
1266
1261
Stroke ? parentStroke,
1267
1262
Color ? currentColor,
1268
- bool leaf,
1269
1263
) {
1270
1264
final String ? rawStroke = getAttribute (attributes, 'stroke' , def: null );
1271
1265
final String ? rawStrokeOpacity = getAttribute (
@@ -1297,7 +1291,7 @@ class SvgParser {
1297
1291
(parentStroke == null || parentStroke.isEmpty)) {
1298
1292
return null ;
1299
1293
} else if (rawStroke == 'none' ) {
1300
- return leaf ? null : Stroke .empty;
1294
+ return Stroke .empty;
1301
1295
}
1302
1296
1303
1297
Paint ? definitionPaint;
@@ -1339,7 +1333,6 @@ class SvgParser {
1339
1333
Fill ? parentFill,
1340
1334
Color ? defaultFillColor,
1341
1335
Color ? currentColor,
1342
- bool leaf,
1343
1336
) {
1344
1337
final String rawFill = attribute ('fill' , def: '' )! ;
1345
1338
final String ? rawFillOpacity = attribute ('fill-opacity' , def: '1.0' );
@@ -1358,9 +1351,6 @@ class SvgParser {
1358
1351
bounds,
1359
1352
opacity: opacity,
1360
1353
).fill;
1361
- if (definitionFill == Fill .empty && leaf) {
1362
- return null ;
1363
- }
1364
1354
return definitionFill;
1365
1355
}
1366
1356
@@ -1377,7 +1367,7 @@ class SvgParser {
1377
1367
return null ;
1378
1368
}
1379
1369
if (rawFill == 'none' ) {
1380
- return leaf ? null : Fill .empty;
1370
+ return Fill .empty;
1381
1371
}
1382
1372
1383
1373
return Fill (
@@ -1408,8 +1398,9 @@ class SvgParser {
1408
1398
/// Parses a `fill-rule` attribute into a [PathFillType] .
1409
1399
PathFillType ? parseFillRule ([
1410
1400
String attr = 'fill-rule' ,
1401
+ String ? def,
1411
1402
]) {
1412
- final String ? rawFillRule = getAttribute (attributes, attr, def: null );
1403
+ final String ? rawFillRule = getAttribute (attributes, attr, def: def );
1413
1404
return parseRawFillRule (rawFillRule);
1414
1405
}
1415
1406
@@ -1478,17 +1469,13 @@ class SvgParser {
1478
1469
bounds,
1479
1470
parentStyle? .stroke,
1480
1471
currentColor,
1481
- leaf,
1482
1472
);
1483
1473
final Fill ? fill = parseFill (
1484
1474
bounds,
1485
1475
parentStyle? .fill,
1486
1476
defaultFillColor,
1487
1477
currentColor,
1488
- leaf,
1489
1478
);
1490
- assert (! leaf || fill != Fill .empty);
1491
- assert (! leaf || stroke != Stroke .empty);
1492
1479
return Paint (
1493
1480
blendMode: _blendModes[getAttribute (attributes, 'mix-blend-mode' )! ],
1494
1481
stroke: stroke,
@@ -1650,21 +1637,22 @@ void _reportMissingDef(String? key, String? href, String methodName) {
1650
1637
].join ('\n ,' ));
1651
1638
}
1652
1639
1653
- // TODO(dnfield): remove/fix this
1654
1640
class _DrawableDefinitionServer {
1655
1641
static const String emptyUrlIri = 'url(#)' ;
1656
1642
final Map <String , Node > _drawables = < String , Node > {};
1657
1643
final Map <String , Shader > _shaders = < String , Shader > {};
1644
+ final Map <String , List <Path >> _clips = < String , List <Path >> {};
1658
1645
1659
1646
Node ? getDrawable (String ref) => _drawables[ref];
1660
- Shader ? getShader (String ref) => _shaders[ref];
1661
- List <Path >? getClipPath (String ref) => null ;
1662
- T ? getGradient <T extends Shader >(String ref) => null ;
1647
+ List <Path >? getClipPath (String ref) => _clips[ref];
1648
+ T ? getGradient <T extends Shader >(String ref) => _shaders[ref] as T ;
1663
1649
void addGradient <T extends Shader >(String ref, T gradient) {
1664
1650
_shaders[ref] = gradient;
1665
1651
}
1666
1652
1667
- void addClipPath (String ref, List <Path > paths) {}
1653
+ void addClipPath (String ref, List <Path > paths) {
1654
+ _clips[ref] = paths;
1655
+ }
1668
1656
1669
1657
void addDrawable (String ref, Node drawable) {
1670
1658
_drawables[ref] = drawable;
0 commit comments