public static FrameworkElement GetElement(SvgElement svg) { if (svg.GetType() == typeof(SvgPath)) { return(GetPath((SvgPath)svg)); } else if (svg.GetType() == typeof(SvgRectangle)) { return(GetRectangle((SvgRectangle)svg)); } else if (svg.GetType() == typeof(SvgCircle)) { return(GetCircle((SvgCircle)svg)); } else if (svg.GetType() == typeof(SvgPolygon)) { return(GetPolygon((SvgPolygon)svg)); } else { string peter = "lol"; //throw new NotImplementedException(""); return(null); } }
private void SetAttributes(XmlReader reader, SvgElement element) { while (reader.MoveToNextAttribute()) { // Ignore some things, at least for now if ((element.ElementName == "svg") && (reader.LocalName == "xmlns")) { // TODO - figure out how to handle the SVG namespace continue; } // Find the corresponding property, if possible var propInfo = ReflectionCache.GetPropertyInfo(element.GetType(), reader.LocalName); if (propInfo != null) { var converter = TypeDescriptor.GetConverter(propInfo.PropertyType); propInfo.SetValue(element, converter.ConvertFrom(reader.Value)); } else { Trace.TraceWarning("Unhandled {0} attribute: {1}", element.ElementName, reader.LocalName); element.ExtraAttributes.Add(reader.LocalName, reader.Value); } } }
/// <exception cref="ArgumentNullException"><paramref name="svgElement" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="sourceMatrix" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="viewMatrix" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="container" /> is <see langword="null" />.</exception> protected virtual void TranslateSvgElement([NotNull] SvgElement svgElement, [NotNull] Matrix sourceMatrix, [NotNull] Matrix viewMatrix, [NotNull] TContainer container) { if (svgElement == null) { throw new ArgumentNullException(nameof(svgElement)); } if (sourceMatrix == null) { throw new ArgumentNullException(nameof(sourceMatrix)); } if (viewMatrix == null) { throw new ArgumentNullException(nameof(viewMatrix)); } if (container == null) { throw new ArgumentNullException(nameof(container)); } var type = svgElement.GetType(); var svgElementTranslator = this.GetTranslator(type); svgElementTranslator?.Translate(svgElement, sourceMatrix, viewMatrix, container); }
//fill the pins recursive with data private void FillRecursive(SvgElement elem, int level) { FElementsOut.Add(elem); FElementTypeOut.Add(elem.GetType().Name.Replace("Svg", "")); FElementLevelOut.Add(level); FElementNameOut.Add(elem.ID); foreach (var child in elem.Children) { FillRecursive(child, level + 1); } }
//fill the pins recursive with data private void FillRecursive(SvgElement elem, int level) { FElementsOut.Add(elem); FElementTypeOut.Add(elem.GetType().Name.Replace("Svg", "")); FElementLevelOut.Add(level); FElementIDOut.Add(elem.ID); var className = ""; if (elem.CustomAttributes.ContainsKey("class")) { className = elem.CustomAttributes["class"]; } FElementClassOut.Add(className); foreach (var child in elem.Children) { FillRecursive(child, level + 1); } }
public override SvgPathSegList DefaultVisit(SvgElement element) => throw new NotSupportedException($"Element of type '{element?.GetType()}' can't be converted to a path segment");
public static string GetName(this SvgElement element) { return(element.GetType().GetCustomAttribute <SvgElementAttribute>()?.ElementName ?? ElementNameGetter?.Invoke(element, null) as string ?? element.GetType().Name); }
/// <summary> /// Get a title for a specified svg element. /// </summary> private static string GetLayerTitle(SvgElement element) { var layerName = element.ID; if (element.CustomAttributes != null) { // get custom title attributes. foreach (var titleAttribute in allowedTitles) { string title; if (element.CustomAttributes.TryGetValue(titleAttribute, out title)) { if (!string.IsNullOrEmpty(title)) { layerName = title; return(layerName); } } } // Get child title tag if (element.Children != null) { var title = element.Children.FirstOrDefault(p => p is SvgTitle); if (title != null && !string.IsNullOrEmpty(title.Content)) { layerName = title.Content; return(layerName); } } } if (string.IsNullOrEmpty(layerName)) { var prop = typeof(SvgElement).GetProperty("ElementName", BindingFlags.NonPublic | BindingFlags.Instance); if (prop != null) { var getter = prop.GetGetMethod(nonPublic: true); layerName = getter.Invoke(element, null) as string; } if (string.IsNullOrEmpty(layerName)) { layerName = element.GetType().Name; } // Generate more meanfull name for a svg use node. Add reference element name in a case if it's local document. var useElement = element as SvgUse; if (useElement != null && useElement.ReferencedElement != null && !string.IsNullOrEmpty(useElement.ReferencedElement.OriginalString)) { var str = useElement.ReferencedElement.OriginalString.Trim(); if (str.StartsWith("#")) { layerName += str.Replace('#', ' '); } } // Genearte more meanfull name for a svg text. var text = element as SvgTextBase; if (text != null && !string.IsNullOrEmpty(text.Text)) { var textToUse = text.Text; if (text.Text.Length > 35) { textToUse = text.Text.Substring(0, 35); } layerName += " " + textToUse; } } return(layerName); }
public override PageElement DefaultVisit(SvgElement element) => throw new NotSupportedException($"SVG Element of type '{element?.GetType()}' not supported by DynamicPdf");