@@ -331,9 +331,25 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
331331 var elementPath = ReadElement ( e ) ;
332332 if ( elementPath == null )
333333 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+
335351 string fillId = e . Attribute ( "fill" ) ? . Value ;
336- object addFill = null ;
352+ object addFill = null ;
337353 if ( ! string . IsNullOrWhiteSpace ( fillId ) && fills . TryGetValue ( fillId , out addFill ) )
338354 {
339355 var x = ReadNumber ( e . Attribute ( "x" ) ) ;
@@ -405,28 +421,11 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
405421 gradientPaint . TryDispose ( ) ;
406422 }
407423 }
424+ else if ( fill != null )
425+ canvas . DrawPath ( elementPath , fill ) ;
426+ if ( stroke != null )
427+ canvas . DrawPath ( elementPath , stroke ) ;
408428
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- }
430429 break ;
431430 }
432431 case "g" :
@@ -478,18 +477,22 @@ private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fi
478477 var href = ReadHref ( e ) ;
479478 if ( href != null )
480479 {
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 ;
486486
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+ }
489494
490495 ReadElement ( href , canvas , stroke ? . Clone ( ) , fill ? . Clone ( ) ) ;
491-
492- canvas . Restore ( ) ;
493496 }
494497 }
495498 break ;
@@ -1140,19 +1143,18 @@ private void ReadPaints(Dictionary<string, string> style, ref SKPaint strokePain
11401143 var urlM = urlRe . Match ( fill ) ;
11411144 if ( urlM . Success )
11421145 {
1143- var id = urlM . Groups [ 1 ] . Value . Trim ( ) ;
1144-
1146+ var id = urlM . Groups [ 1 ] . Value . Trim ( ) ;
11451147 if ( defs . TryGetValue ( id , out XElement defE ) )
11461148 {
1147- switch ( defE . Name . LocalName )
1149+ switch ( defE . Name . LocalName . ToLower ( ) )
11481150 {
1149- case "linearGradient " :
1151+ case "lineargradient " :
11501152 fillPaint . Color = SKColors . Transparent ;
11511153 if ( ! fills . ContainsKey ( fill ) )
11521154 fills . Add ( fill , ReadLinearGradient ( defE ) ) ;
11531155 read = true ;
11541156 break ;
1155- case "radialGradient " :
1157+ case "radialgradient " :
11561158 fillPaint . Color = SKColors . Transparent ;
11571159 if ( ! fills . ContainsKey ( fill ) )
11581160 fills . Add ( fill , ReadRadialGradient ( defE ) ) ;
@@ -1197,7 +1199,6 @@ private SKPaint CreatePaint(bool stroke = false)
11971199 {
11981200 IsAntialias = true ,
11991201 IsStroke = stroke ,
1200- Color = SKColors . Black
12011202 } ;
12021203
12031204 if ( stroke )
@@ -1206,6 +1207,11 @@ private SKPaint CreatePaint(bool stroke = false)
12061207 strokePaint . StrokeMiter = 4f ;
12071208 strokePaint . StrokeJoin = SKStrokeJoin . Miter ;
12081209 strokePaint . StrokeCap = SKStrokeCap . Butt ;
1210+ strokePaint . Color = SKColors . Transparent ;
1211+ }
1212+ else
1213+ {
1214+ strokePaint . Color = SKColors . Black ;
12091215 }
12101216
12111217 return strokePaint ;
0 commit comments