//========================================================================== public SvgRectElement(SvgDocument document, SvgBaseElement parent, XElement rectElement) : base(document, parent, rectElement) { XAttribute x_attribute = rectElement.Attribute("x"); SvgCoordinate.TryUpdate(ref X, x_attribute?.Value); XAttribute y_attribute = rectElement.Attribute("y"); SvgCoordinate.TryUpdate(ref Y, y_attribute?.Value); XAttribute width_attribute = rectElement.Attribute("width"); SvgLength.TryUpdate(ref Width, width_attribute?.Value); XAttribute height_attribute = rectElement.Attribute("height"); SvgLength.TryUpdate(ref Height, height_attribute?.Value); XAttribute rx_attribute = rectElement.Attribute("rx"); SvgCoordinate.TryUpdate(ref CornerRadiusX, rx_attribute?.Value); XAttribute ry_attribute = rectElement.Attribute("ry"); SvgCoordinate.TryUpdate(ref CornerRadiusY, ry_attribute?.Value); }
//========================================================================== public SvgFEGaussianBlurElement(SvgDocument document, SvgBaseElement parent, XElement feGaussianBlurElement) : base(document, parent, feGaussianBlurElement) { XAttribute std_deviation_attribute = feGaussianBlurElement.Attribute("stdDeviation"); SvgCoordinate.TryUpdate(ref StdDeviation, std_deviation_attribute?.Value); }
//========================================================================== public SvgCircleElement(SvgDocument document, SvgBaseElement parent, XElement circleElement) : base(document, parent, circleElement) { XAttribute cx_attribute = circleElement.Attribute("cx"); SvgCoordinate.TryUpdate(ref CenterX, cx_attribute?.Value); XAttribute cy_attribute = circleElement.Attribute("cy"); SvgCoordinate.TryUpdate(ref CenterY, cy_attribute?.Value); XAttribute r_attribute = circleElement.Attribute("r"); SvgLength.TryUpdate(ref Radius, r_attribute?.Value); }
//========================================================================== public SvgTSpanElement(SvgDocument document, SvgBaseElement parent, XElement svgElement) : base(document, parent, svgElement) { if (svgElement.FirstNode != null && svgElement.FirstNode.NodeType == XmlNodeType.Text) { this.Text = svgElement.FirstNode.ToString(); } var xAttr = svgElement.Attribute("x"); SvgCoordinate.TryUpdate(ref X, xAttr?.Value); var yAttr = svgElement.Attribute("y"); SvgCoordinate.TryUpdate(ref Y, yAttr?.Value); }
//========================================================================== public SvgEllipseElement(SvgDocument document, SvgBaseElement parent, XElement ellipseElement) : base(document, parent, ellipseElement) { XAttribute cx_attribute = ellipseElement.Attribute("cx"); SvgCoordinate.TryUpdate(ref CenterX, cx_attribute?.Value); XAttribute cy_attribute = ellipseElement.Attribute("cy"); SvgCoordinate.TryUpdate(ref CenterY, cy_attribute?.Value); XAttribute rx_attribute = ellipseElement.Attribute("rx"); SvgCoordinate.TryUpdate(ref RadiusX, rx_attribute?.Value); XAttribute ry_attribute = ellipseElement.Attribute("ry"); SvgCoordinate.TryUpdate(ref RadiusY, ry_attribute?.Value); }
//========================================================================== public SvgLinearGradientElement(SvgDocument document, SvgBaseElement parent, XElement linearGradientElement) : base(document, parent, linearGradientElement) { XAttribute x1_attribute = linearGradientElement.Attribute("x1"); SvgCoordinate.TryUpdate(ref X1, x1_attribute?.Value); XAttribute y1_attribute = linearGradientElement.Attribute("y1"); SvgCoordinate.TryUpdate(ref Y1, y1_attribute?.Value); XAttribute x2_attribute = linearGradientElement.Attribute("x2"); SvgCoordinate.TryUpdate(ref X2, x2_attribute?.Value); XAttribute y2_attribute = linearGradientElement.Attribute("y2"); SvgCoordinate.TryUpdate(ref Y2, y2_attribute?.Value); }
//========================================================================== public SvgRadialGradientElement(SvgDocument document, SvgBaseElement parent, XElement radialGradientElement) : base(document, parent, radialGradientElement) { XAttribute cx_attribute = radialGradientElement.Attribute("cx"); SvgCoordinate.TryUpdate(ref CX, cx_attribute?.Value); XAttribute cy_attribute = radialGradientElement.Attribute("cy"); SvgCoordinate.TryUpdate(ref CY, cy_attribute?.Value); XAttribute r_attribute = radialGradientElement.Attribute("r"); SvgCoordinate.TryUpdate(ref R, r_attribute?.Value); XAttribute fx_attribute = radialGradientElement.Attribute("fx"); SvgCoordinate.TryUpdate(ref FX, fx_attribute?.Value); XAttribute fy_attribute = radialGradientElement.Attribute("fy"); SvgCoordinate.TryUpdate(ref FY, fy_attribute?.Value); }
//========================================================================== public SvgTextElement(SvgDocument document, SvgBaseElement parent, XElement svgElement) : base(document, parent, svgElement) { var fontFamilyAttr = svgElement.Attribute("font-family"); var fontFamilyStr = fontFamilyAttr != null ? fontFamilyAttr.Value : "sans-serif"; var fontSizeAttr = svgElement.Attribute("font-size"); var fontSizeStr = fontSizeAttr != null ? fontSizeAttr.Value : "12px"; var fontStretchAttr = svgElement.Attribute("font-stretch"); var fontStretchStr = fontStretchAttr != null ? fontStretchAttr.Value : "normal"; var fontStyleAttr = svgElement.Attribute("font-style"); var fontStyleStr = fontStyleAttr != null ? fontStyleAttr.Value : "normal"; var fontWeightAttr = svgElement.Attribute("font-weight"); var fontWeightStr = fontWeightAttr != null ? fontWeightAttr.Value : "normal"; var letterSpacingAttr = svgElement.Attribute("letter-spacing"); var letterSpacingStr = letterSpacingAttr != null ? letterSpacingAttr.Value : "0px"; var lineHeightAttr = svgElement.Attribute("line-height"); var lineHeightStr = lineHeightAttr != null ? lineHeightAttr.Value : "100%"; var wordSpacingAttr = svgElement.Attribute("word-spacing"); var wordSpacingStr = wordSpacingAttr != null ? wordSpacingAttr.Value : "0px"; var textAnchorAttr = svgElement.Attribute("text-anchor"); TextAnchor = textAnchorAttr != null ? textAnchorAttr.Value : "start"; var xAttr = svgElement.Attribute("x"); SvgCoordinate.TryUpdate(ref X, xAttr?.Value); var yAttr = svgElement.Attribute("y"); SvgCoordinate.TryUpdate(ref Y, yAttr?.Value); var ff = new FontFamily(fontFamilyStr); var fs = fontStyleStr.TryConvert(FontStyles.Normal); var fw = fontWeightStr.TryConvert(FontWeights.Normal); var fc = fontStretchStr.TryConvert(FontStretches.Medium); this.FontSize = fontSizeStr.TryConvert <double, LengthConverter>(12.0); this.Typeface = new Typeface(ff, fs, fw, fc); var firstSubNode = svgElement.FirstNode; if (firstSubNode != null) { if (firstSubNode.NodeType == XmlNodeType.Text) { this.Text = ((XText)firstSubNode).Value; } else { this.Text = null; } } }
//========================================================================== public SvgImageElement(SvgDocument document, SvgBaseElement parent, XElement imageElement) : base(document, parent, imageElement) { XAttribute x_attribute = imageElement.Attribute("x"); SvgCoordinate.TryUpdate(ref X, x_attribute?.Value); XAttribute y_attribute = imageElement.Attribute("y"); SvgCoordinate.TryUpdate(ref Y, y_attribute?.Value); XAttribute width_attribute = imageElement.Attribute("width"); SvgLength.TryUpdate(ref Width, width_attribute?.Value); XAttribute height_attribute = imageElement.Attribute("height"); SvgLength.TryUpdate(ref Height, height_attribute?.Value); XAttribute href_attribute = imageElement.Attribute(XName.Get("href", "http://www.w3.org/1999/xlink")); if (href_attribute != null) { string reference = href_attribute.Value.TrimStart(); if (reference.StartsWith("data:")) { reference = reference.Substring(5).TrimStart(); int index = reference.IndexOf(";"); if (index > -1) { string type = reference.Substring(0, index).Trim(); reference = reference.Substring(index + 1); index = reference.IndexOf(","); string encoding = reference.Substring(0, index).Trim(); reference = reference.Substring(index + 1).TrimStart(); switch (encoding) { case "base64": Data = Convert.FromBase64String(reference); break; default: throw new NotSupportedException(String.Format("Unsupported encoding: {0}", encoding)); } string[] type_tokens = type.Split('/'); if (type_tokens.Length != 2) { throw new NotSupportedException(String.Format("Unsupported type: {0}", type)); } type_tokens[0] = type_tokens[0].Trim(); if (type_tokens[0] != "image") { throw new NotSupportedException(String.Format("Unsupported type: {0}", type)); } switch (type_tokens[1].Trim()) { case "jpeg": DataType = "jpeg"; break; case "png": DataType = "png"; break; case "svg+xml": DataType = "svg+xml"; break; default: throw new NotSupportedException(String.Format("Unsupported type: {0}", type)); } } } } }