[BUG] attributes are not properly passed on to child elements
Describe the bug Settings like 'fill' in the
To Reproduce Steps to reproduce the behavior:
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="red"
>
<path stroke-width="2" d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
</svg>
XAML:
<svg:SVGImage
UriSource="/Resources/Images/edit.svg"
SizeType="ViewBoxToSizeNoStretch" />
Expected behavior I expect the same result what you get when:
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path
fill="none"
stroke="red"
stroke-width="2" d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
</svg>
Screenshots I get:
but I expect:
Additional context This example is based on this svg: https://github.com/tabler/tabler-icons/blob/main/icons/outline/edit.svg
Note that the attributes of <g> do pass on to its children.
I'm currently not actively using or working on this library, so you need to look for the issue yourself or hope someone fixes it. I've you look after it and create a pull req, I'll look to merge.
For documentation, this is the dirty fix:
private List<Shape> Parse(XmlNode node)
{
var vb = node.Attributes.GetNamedItem("viewBox");
if (vb != null)
{
var cord = vb.Value.Split(' ');
var cult = CultureInfo.InvariantCulture;
this.ViewBox = new Rect(double.Parse(cord[0], cult),
double.Parse(cord[1], cult), double.Parse(cord[2], cult), double.Parse(cord[3], cult));
}
this.Size = new Size(XmlUtil.AttrValue(node, "width", 300), XmlUtil.AttrValue(node, "height", 150));
var lstElements = new List<Shape>();
if (node == null || (node.Name != SVGTags.sSvg && node.Name != SVGTags.sPattern))
throw new FormatException("Not a valide SVG node");
var svgGroup = new Group(this, node, null);
lstElements.Add(svgGroup);
foreach (XmlNode childnode in node.ChildNodes)
Group.AddToList(this, svgGroup.m_elements, childnode, svgGroup);
return lstElements;
}
(in SVGImage\SVG\SVG.cs) I rather not do the actual edit myself since I'm not comfortable working in this codebase.
fixed in #107