//========================================================================== public SvgEllipseElement(SvgDocument document, SvgBaseElement parent, XElement ellipseElement) : base(document, parent, ellipseElement) { XAttribute cx_attribute = ellipseElement.Attribute("cx"); if (cx_attribute != null) { CenterX = SvgCoordinate.Parse(cx_attribute.Value); } XAttribute cy_attribute = ellipseElement.Attribute("cy"); if (cy_attribute != null) { CenterY = SvgCoordinate.Parse(cy_attribute.Value); } XAttribute rx_attribute = ellipseElement.Attribute("rx"); if (rx_attribute != null) { RadiusX = SvgCoordinate.Parse(rx_attribute.Value); } XAttribute ry_attribute = ellipseElement.Attribute("ry"); if (ry_attribute != null) { RadiusY = SvgCoordinate.Parse(ry_attribute.Value); } }
//========================================================================== public SvgLinearGradientElement(SvgDocument document, SvgBaseElement parent, XElement linearGradientElement) : base(document, parent, linearGradientElement) { XAttribute x1_attribute = linearGradientElement.Attribute("x1"); if (x1_attribute != null) { X1 = SvgCoordinate.Parse(x1_attribute.Value); } XAttribute y1_attribute = linearGradientElement.Attribute("y1"); if (y1_attribute != null) { Y1 = SvgCoordinate.Parse(y1_attribute.Value); } XAttribute x2_attribute = linearGradientElement.Attribute("x2"); if (x2_attribute != null) { X2 = SvgCoordinate.Parse(x2_attribute.Value); } XAttribute y2_attribute = linearGradientElement.Attribute("y2"); if (y2_attribute != null) { Y2 = SvgCoordinate.Parse(y2_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 xAttr = svgElement.Attribute("x"); this.X = xAttr != null?SvgCoordinate.Parse(xAttr.Value) : null; var yAttr = svgElement.Attribute("y"); this.Y = yAttr != null?SvgCoordinate.Parse(yAttr.Value) : null; 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 = firstSubNode.ToString(); } else { this.Text = null; } } }
//========================================================================== public SvgFEGaussianBlurElement(SvgDocument document, SvgBaseElement parent, XElement feGaussianBlurElement) : base(document, parent, feGaussianBlurElement) { XAttribute std_deviation_attribute = feGaussianBlurElement.Attribute("stdDeviation"); if (std_deviation_attribute != null) { StdDeviation = SvgCoordinate.Parse(std_deviation_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"); this.X = xAttr != null?SvgCoordinate.Parse(xAttr.Value) : null; var yAttr = svgElement.Attribute("y"); this.Y = yAttr != null?SvgCoordinate.Parse(yAttr.Value) : null; }
//========================================================================== public SvgRectElement(SvgDocument document, SvgBaseElement parent, XElement rectElement) : base(document, parent, rectElement) { XAttribute x_attribute = rectElement.Attribute("x"); if (x_attribute != null) { X = SvgCoordinate.Parse(x_attribute.Value); } XAttribute y_attribute = rectElement.Attribute("y"); if (y_attribute != null) { Y = SvgCoordinate.Parse(y_attribute.Value); } XAttribute width_attribute = rectElement.Attribute("width"); if (width_attribute != null) { Width = SvgLength.Parse(width_attribute.Value); } XAttribute height_attribute = rectElement.Attribute("height"); if (height_attribute != null) { Height = SvgLength.Parse(height_attribute.Value); } XAttribute rx_attribute = rectElement.Attribute("rx"); if (rx_attribute != null) { CornerRadiusX = SvgCoordinate.Parse(rx_attribute.Value); } XAttribute ry_attribute = rectElement.Attribute("ry"); if (ry_attribute != null) { CornerRadiusY = SvgCoordinate.Parse(ry_attribute.Value); } }
//========================================================================== public SvgRadialGradientElement(SvgDocument document, SvgBaseElement parent, XElement radialGradientElement) : base(document, parent, radialGradientElement) { XAttribute cx_attribute = radialGradientElement.Attribute("cx"); if (cx_attribute != null) { CX = SvgCoordinate.Parse(cx_attribute.Value); } XAttribute cy_attribute = radialGradientElement.Attribute("cy"); if (cy_attribute != null) { CY = SvgCoordinate.Parse(cy_attribute.Value); } XAttribute r_attribute = radialGradientElement.Attribute("r"); if (r_attribute != null) { R = SvgCoordinate.Parse(r_attribute.Value); } XAttribute fx_attribute = radialGradientElement.Attribute("fx"); if (fx_attribute != null) { FX = SvgCoordinate.Parse(fx_attribute.Value); } XAttribute fy_attribute = radialGradientElement.Attribute("fy"); if (fy_attribute != null) { FY = SvgCoordinate.Parse(fy_attribute.Value); } }
//========================================================================== public SvgCircleElement(SvgDocument document, SvgBaseElement parent, XElement circleElement) : base(document, parent, circleElement) { XAttribute cx_attribute = circleElement.Attribute("cx"); if (cx_attribute != null) { CenterX = SvgCoordinate.Parse(cx_attribute.Value); } XAttribute cy_attribute = circleElement.Attribute("cy"); if (cy_attribute != null) { CenterY = SvgCoordinate.Parse(cy_attribute.Value); } XAttribute r_attribute = circleElement.Attribute("r"); if (r_attribute != null) { Radius = SvgLength.Parse(r_attribute.Value); } }
//========================================================================== public SvgImageElement(SvgDocument document, SvgBaseElement parent, XElement imageElement) : base(document, parent, imageElement) { XAttribute x_attribute = imageElement.Attribute("x"); if (x_attribute != null) { X = SvgCoordinate.Parse(x_attribute.Value); } XAttribute y_attribute = imageElement.Attribute("y"); if (y_attribute != null) { Y = SvgCoordinate.Parse(y_attribute.Value); } XAttribute width_attribute = imageElement.Attribute("width"); if (width_attribute != null) { Width = SvgLength.Parse(width_attribute.Value); } XAttribute height_attribute = imageElement.Attribute("height"); if (height_attribute != null) { Height = SvgLength.Parse(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; default: throw new NotSupportedException(String.Format("Unsupported type: {0}", type)); } } } } }