@@ -331,9 +331,25 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
331
331
var elementPath = ReadElement ( e ) ;
332
332
if ( elementPath == null )
333
333
break ;
334
-
334
+
335
+ if ( mask != null )
336
+ {
337
+ canvas . SaveLayer ( new SKPaint ( ) ) ;
338
+ foreach ( var gElement in mask . Element . Elements ( ) )
339
+ {
340
+ ReadElement ( gElement , canvas , mask . Fill . Clone ( ) , mask . Fill . Clone ( ) ) ;
341
+ }
342
+ using ( var paint = fill . Clone ( ) )
343
+ {
344
+ paint . BlendMode = SKBlendMode . SrcIn ;
345
+ canvas . DrawPath ( elementPath , paint ) ;
346
+ }
347
+ canvas . Restore ( ) ;
348
+ return ;
349
+ }
350
+
335
351
string fillId = e . Attribute ( "fill" ) ? . Value ;
336
- object addFill = null ;
352
+ object addFill = null ;
337
353
if ( ! string . IsNullOrWhiteSpace ( fillId ) && fills . TryGetValue ( fillId , out addFill ) )
338
354
{
339
355
var x = ReadNumber ( e . Attribute ( "x" ) ) ;
@@ -405,28 +421,11 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
405
421
gradientPaint . TryDispose ( ) ;
406
422
}
407
423
}
424
+ else if ( fill != null )
425
+ canvas . DrawPath ( elementPath , fill ) ;
426
+ if ( stroke != null )
427
+ canvas . DrawPath ( elementPath , stroke ) ;
408
428
409
- if ( mask != null )
410
- {
411
- canvas . SaveLayer ( new SKPaint ( ) ) ;
412
- foreach ( var gElement in mask . Element . Elements ( ) )
413
- {
414
- ReadElement ( gElement , canvas , mask . Fill . Clone ( ) , mask . Fill . Clone ( ) ) ;
415
- }
416
- using ( var paint = fill . Clone ( ) )
417
- {
418
- paint . BlendMode = SKBlendMode . SrcIn ;
419
- canvas . DrawPath ( elementPath , paint ) ;
420
- }
421
- canvas . Restore ( ) ;
422
- }
423
- else
424
- {
425
- if ( fill != null )
426
- canvas . DrawPath ( elementPath , fill ) ;
427
- if ( stroke != null )
428
- canvas . DrawPath ( elementPath , stroke ) ;
429
- }
430
429
break ;
431
430
}
432
431
case "g" :
@@ -478,18 +477,22 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
478
477
var href = ReadHref ( e ) ;
479
478
if ( href != null )
480
479
{
481
- // TODO: copy/process other attributes
482
-
483
- var x = ReadNumber ( e . Attribute ( "x" ) ) ;
484
- var y = ReadNumber ( e . Attribute ( "y" ) ) ;
485
- var useTransform = SKMatrix . MakeTranslation ( x , y ) ;
480
+ // create a deep copy as we will copy attributes
481
+ href = new XElement ( href ) ;
482
+ var attributes = e . Attributes ( ) ;
483
+ foreach ( var attribute in attributes )
484
+ {
485
+ var name = attribute . Name . LocalName ;
486
486
487
- canvas . Save ( ) ;
488
- canvas . Concat ( ref useTransform ) ;
487
+ if ( ! name . Contains ( "href" , StringComparison . OrdinalIgnoreCase )
488
+ && ! name . Equals ( "id" , StringComparison . OrdinalIgnoreCase )
489
+ && ! name . Equals ( "transform" , StringComparison . OrdinalIgnoreCase ) )
490
+ {
491
+ href . SetAttributeValue ( attribute . Name , attribute . Value ) ;
492
+ }
493
+ }
489
494
490
495
ReadElement ( href , canvas , stroke ? . Clone ( ) , fill ? . Clone ( ) ) ;
491
-
492
- canvas . Restore ( ) ;
493
496
}
494
497
}
495
498
break ;
@@ -1140,19 +1143,18 @@ private void ReadPaints(Dictionary<string, string> style, ref SKPaint strokePain
1140
1143
var urlM = urlRe . Match ( fill ) ;
1141
1144
if ( urlM . Success )
1142
1145
{
1143
- var id = urlM . Groups [ 1 ] . Value . Trim ( ) ;
1144
-
1146
+ var id = urlM . Groups [ 1 ] . Value . Trim ( ) ;
1145
1147
if ( defs . TryGetValue ( id , out XElement defE ) )
1146
1148
{
1147
- switch ( defE . Name . LocalName )
1149
+ switch ( defE . Name . LocalName . ToLower ( ) )
1148
1150
{
1149
- case "linearGradient " :
1151
+ case "lineargradient " :
1150
1152
fillPaint . Color = SKColors . Transparent ;
1151
1153
if ( ! fills . ContainsKey ( fill ) )
1152
1154
fills . Add ( fill , ReadLinearGradient ( defE ) ) ;
1153
1155
read = true ;
1154
1156
break ;
1155
- case "radialGradient " :
1157
+ case "radialgradient " :
1156
1158
fillPaint . Color = SKColors . Transparent ;
1157
1159
if ( ! fills . ContainsKey ( fill ) )
1158
1160
fills . Add ( fill , ReadRadialGradient ( defE ) ) ;
@@ -1197,7 +1199,6 @@ private SKPaint CreatePaint(bool stroke = false)
1197
1199
{
1198
1200
IsAntialias = true ,
1199
1201
IsStroke = stroke ,
1200
- Color = SKColors . Black
1201
1202
} ;
1202
1203
1203
1204
if ( stroke )
@@ -1206,6 +1207,11 @@ private SKPaint CreatePaint(bool stroke = false)
1206
1207
strokePaint . StrokeMiter = 4f ;
1207
1208
strokePaint . StrokeJoin = SKStrokeJoin . Miter ;
1208
1209
strokePaint . StrokeCap = SKStrokeCap . Butt ;
1210
+ strokePaint . Color = SKColors . Transparent ;
1211
+ }
1212
+ else
1213
+ {
1214
+ strokePaint . Color = SKColors . Black ;
1209
1215
}
1210
1216
1211
1217
return strokePaint ;
0 commit comments