/// <summary> /// Generate a shape /// </summary> private static XElement GeneratePath(GraphicPath graphicPath, XNamespace ns, XElement definitions, ref int definitionsCount) { var pathElement = new XElement(ns + "path"); var pathStr = StreamSourceGenerator.GenerateStreamGeometry(graphicPath.Geometry, false); pathElement.Add(new XAttribute("d", pathStr)); SetColors(graphicPath, pathElement, ns, definitions, ref definitionsCount); return(pathElement); }
/// <summary> /// Generate a visual recursively to xml /// </summary> private static XElement Generate(GraphicVisual visual, XNamespace ns, XElement definitions, ref int definitionsCount) { XElement element = null; switch (visual) { case GraphicGroup group: { element = new XElement(ns + "g"); if (!DoubleUtilities.IsEqual(group.Opacity, 1)) { element.Add(new XAttribute("opacity", DoubleUtilities.FormatString(group.Opacity))); } if (group.Clip != null) { var clipElement = new XElement(ns + "clipPath"); definitions.Add(clipElement); definitionsCount++; string defId = $"clip{definitionsCount}"; element.Add(new XAttribute("clip-path", $"url(#{defId})")); clipElement.Add(new XAttribute("id", defId)); var pathElement = new XElement(ns + "path"); clipElement.Add(pathElement); var pathStr = StreamSourceGenerator.GenerateStreamGeometry(group.Clip, false); pathElement.Add(new XAttribute("d", pathStr)); } foreach (var childVisual in group.Childreen) { var path = Generate(childVisual, ns, definitions, ref definitionsCount); element.Add(path); } break; } case GraphicPath graphicPath: { element = GeneratePath(graphicPath, ns, definitions, ref definitionsCount); break; } } return(element); }