SVGImage icon indicating copy to clipboard operation
SVGImage copied to clipboard

[BUG] attributes are not properly passed on to child elements

Open Ahrkylien opened this issue 10 months ago • 3 comments

Describe the bug Settings like 'fill' in the are not being applied to its child

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:

Image but I expect:

Image

Additional context This example is based on this svg: https://github.com/tabler/tabler-icons/blob/main/icons/outline/edit.svg

Ahrkylien avatar Mar 23 '25 12:03 Ahrkylien

Note that the attributes of <g> do pass on to its children.

Ahrkylien avatar Mar 23 '25 12:03 Ahrkylien

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.

jogibear9988 avatar Mar 26 '25 11:03 jogibear9988

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.

Ahrkylien avatar Mar 26 '25 19:03 Ahrkylien

fixed in #107

jogibear9988 avatar Aug 09 '25 17:08 jogibear9988