//========================================================================== 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 SvgFilterElement(SvgDocument document, SvgBaseElement parent, XElement filterElement) : base(document, parent, filterElement) { foreach(XElement element in from element in filterElement.Elements() where element.Name.NamespaceName == "http://www.w3.org/2000/svg" select element) switch(element.Name.LocalName) { case "feGaussianBlur": FilterEffects.Add(new SvgFEGaussianBlurElement(document, this, element)); break; case "feBlend": FilterEffects.Add(new SvgFEBlendElement(document, this, element)); break; case "feColorMatrix": FilterEffects.Add(new SvgFEColorMatrixElement(document, this, element)); break; default: throw new NotImplementedException(string.Format("Unhandled element: {0}", element)); } }
//========================================================================== public SvgPatternElement(SvgDocument document, SvgBaseElement parent, XElement patternElement) : base(document, parent, patternElement) { XAttribute pattern_transform_attribute = patternElement.Attribute("patternTransform"); if(pattern_transform_attribute != null) PatternTransform = SvgTransform.Parse(pattern_transform_attribute.Value); XAttribute pattern_units_attribute = patternElement.Attribute("patternUnits"); if(pattern_units_attribute != null) switch(pattern_units_attribute.Value) { case "objectBoundingBox": PatternUnits = SvgPatternUnits.ObjectBoundingBox; break; case "userSpaceOnUse": PatternUnits = SvgPatternUnits.UserSpaceOnUse; break; default: throw new NotImplementedException(String.Format("patternUnits value '{0}' is no supported", pattern_units_attribute.Value)); } XAttribute width_attribute = patternElement.Attribute("width"); if(width_attribute != null) Width = SvgLength.Parse(width_attribute.Value); XAttribute height_attribute = patternElement.Attribute("height"); if(height_attribute != null) Height = SvgLength.Parse(height_attribute.Value); }
//========================================================================== 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 SvgPathElement(SvgDocument document, SvgBaseElement parent, XElement pathElement) : base(document, parent, pathElement) { XAttribute d_attribute = pathElement.Attribute("d"); if(d_attribute != null) Data = d_attribute.Value; else Data = null; }
//========================================================================== public SvgGradientBaseElement(SvgDocument document, SvgBaseElement parent, XElement gradientElement) : base(document, parent, gradientElement) { XAttribute gradient_units_attribute = gradientElement.Attribute("gradientUnits"); if(gradient_units_attribute != null) switch(gradient_units_attribute.Value) { case "objectBoundingBox": GradientUnits = SvgGradientUnits.ObjectBoundingBox; break; case "userSpaceOnUse": GradientUnits = SvgGradientUnits.UserSpaceOnUse; break; default: throw new NotImplementedException(String.Format("gradientUnits value '{0}' is no supported", gradient_units_attribute.Value)); } XAttribute gradient_transform_attribute = gradientElement.Attribute("gradientTransform"); if(gradient_transform_attribute != null) Transform = SvgTransform.Parse(gradient_transform_attribute.Value); XAttribute spread_method_attribute = gradientElement.Attribute("spreadMethod"); if(spread_method_attribute != null) switch(spread_method_attribute.Value) { case "pad": SpreadMethod = SvgSpreadMethod.Pad; break; case "reflect": SpreadMethod = SvgSpreadMethod.Reflect; break; case "repeat": SpreadMethod = SvgSpreadMethod.Repeat; break; } foreach(XElement element in from element in gradientElement.Elements() where element.Name.NamespaceName == "http://www.w3.org/2000/svg" select element) switch(element.Name.LocalName) { case "stop": Stops.Add(new SvgStopElement(Document, this, element)); break; default: throw new NotImplementedException(String.Format("Unhandled element: {0}", element)); } }
//========================================================================== public SvgStopElement(SvgDocument document, SvgBaseElement parent, XElement stopElement) : base(document, parent, stopElement) { XAttribute offset_attribute = stopElement.Attribute("offset"); if(offset_attribute != null) Offset = SvgLength.Parse(offset_attribute.Value); XAttribute stop_color_attribute = stopElement.Attribute("stop-color"); if(stop_color_attribute != null) Color = SvgColor.Parse(stop_color_attribute.Value); XAttribute stop_opacity_attribute = stopElement.Attribute("stop-opacity"); if(stop_opacity_attribute != null) Opacity = SvgLength.Parse(stop_opacity_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 SvgFlowRootElement(SvgDocument document, SvgBaseElement parent, XElement flowRootElement) : base(document, parent, flowRootElement) { for(int i = 0; i < Children.Count; ++i) { FlowRegion = Children[i] as SvgFlowRegionElement; if(FlowRegion != null) { Children.RemoveAt(i); break; } } if(FlowRegion == null) throw new NotImplementedException(); }
//========================================================================== public SvgLineElement(SvgDocument document, SvgBaseElement parent, XElement lineElement) : base(document, parent, lineElement) { XAttribute x1_attribute = lineElement.Attribute("x1"); if(x1_attribute != null) X1 = SvgCoordinate.Parse(x1_attribute.Value); XAttribute y1_attribute = lineElement.Attribute("y1"); if(y1_attribute != null) Y1 = SvgCoordinate.Parse(y1_attribute.Value); XAttribute x2_attribute = lineElement.Attribute("x2"); if(x2_attribute != null) X2 = SvgCoordinate.Parse(x2_attribute.Value); XAttribute y2_attribute = lineElement.Attribute("y2"); if(y2_attribute != null) Y2 = SvgCoordinate.Parse(y2_attribute.Value); }
//========================================================================== public SvgMaskElement(SvgDocument document, SvgBaseElement parent, XElement maskElement) : base(document, parent, maskElement) { XAttribute mask_units_attribute = maskElement.Attribute("maskUnits"); if(mask_units_attribute != null) switch(mask_units_attribute.Value) { case "objectBoundingBox": MaskUnits = SvgMaskUnits.ObjectBoundingBox; break; case "userSpaceOnUse": MaskUnits = SvgMaskUnits.UserSpaceOnUse; break; default: throw new NotImplementedException(String.Format("maskUnits value '{0}' is no supported", mask_units_attribute.Value)); } }
//========================================================================== 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 SvgPolylineElement(SvgDocument document, SvgBaseElement parent, XElement polylineElement) : base(document, parent, polylineElement) { XAttribute points_attribute = polylineElement.Attribute("points"); if(points_attribute != null) { List<double> coordinates = new List<double>(); string[] points = points_attribute.Value.Split(',', ' ', '\t'); foreach(string coordinate_value in points) { string coordinate = coordinate_value.Trim(); if(coordinate == "") continue; coordinates.Add(Double.Parse(coordinate, CultureInfo.InvariantCulture.NumberFormat)); } for(int i = 0; i < coordinates.Count - 1; i += 2) Points.Add(new SvgPoint(coordinates[i], coordinates[i + 1])); } }
//========================================================================== protected SvgBaseElement(SvgDocument document, SvgBaseElement parent, XElement element) { Document = document; Parent = parent; // Create attributes from styles... XAttribute style_attribute = element.Attribute("style"); if(style_attribute != null) { foreach(string property in style_attribute.Value.Split(';')) { string[] tokens = property.Split(':'); if(tokens.Length == 2) try { element.SetAttributeValue(tokens[0], tokens[1]); } catch(XmlException) { continue; } } style_attribute.Remove(); } XAttribute id_attribute = element.Attribute("id"); if(id_attribute != null) Document.Elements[Id = id_attribute.Value] = this; XAttribute href_attribute = element.Attribute(XName.Get("href", "http://www.w3.org/1999/xlink")); if(href_attribute != null) { string reference = href_attribute.Value; if(reference.StartsWith("#")) Reference = reference.Substring(1); } Element = element; }
//========================================================================== 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 SvgDrawableContainerBaseElement(SvgDocument document, SvgBaseElement parent, XElement drawableContainerElement) : base(document, parent, drawableContainerElement) { XAttribute viewBox_attribute = drawableContainerElement.Attribute("viewBox"); if (viewBox_attribute != null) { this.ViewBox = SvgViewbox.Parse(viewBox_attribute.Value); } XAttribute opacity_attribute = drawableContainerElement.Attribute("opacity"); if (opacity_attribute != null) { Opacity = SvgLength.Parse(opacity_attribute.Value); } XAttribute transform_attribute = drawableContainerElement.Attribute("transform"); if (transform_attribute != null) { Transform = SvgTransform.Parse(transform_attribute.Value); } XAttribute clip_attribute = drawableContainerElement.Attribute("clip-path"); if (clip_attribute != null) { ClipPath = SvgURL.Parse(clip_attribute.Value); } XAttribute filter_attribute = drawableContainerElement.Attribute("filter"); if (filter_attribute != null) { Filter = SvgURL.Parse(filter_attribute.Value); } XAttribute mask_attribute = drawableContainerElement.Attribute("mask"); if (mask_attribute != null) { Mask = SvgURL.Parse(mask_attribute.Value); } XAttribute display_attribute = drawableContainerElement.Attribute("display"); if (display_attribute != null) { switch (display_attribute.Value) { case "inline": Display = SvgDisplay.Inline; break; case "block": Display = SvgDisplay.Block; break; case "list-item": Display = SvgDisplay.ListItem; break; case "run-in": Display = SvgDisplay.RunIn; break; case "compact": Display = SvgDisplay.Compact; break; case "marker": Display = SvgDisplay.Marker; break; case "table": Display = SvgDisplay.Table; break; case "inline-table": Display = SvgDisplay.InlineTable; break; case "table-row-group": Display = SvgDisplay.TableRowGroup; break; case "table-header-group": Display = SvgDisplay.TableHeaderGroup; break; case "table-footer-group": Display = SvgDisplay.TableFooterGroup; break; case "table-row": Display = SvgDisplay.TableRow; break; case "table-column-group": Display = SvgDisplay.TableColumnGroup; break; case "table-column": Display = SvgDisplay.TableColumn; break; case "table-cell": Display = SvgDisplay.TableCell; break; case "table-caption": Display = SvgDisplay.TableCaption; break; case "none": Display = SvgDisplay.None; break; default: throw new NotImplementedException(); } } XAttribute fill_opacity_attribute = drawableContainerElement.Attribute("fill-opacity"); if (fill_opacity_attribute != null) { FillOpacity = SvgLength.Parse(fill_opacity_attribute.Value); } XAttribute stroke_opacity_attribute = drawableContainerElement.Attribute("stroke-opacity"); if (stroke_opacity_attribute != null) { StrokeOpacity = SvgLength.Parse(stroke_opacity_attribute.Value); } XAttribute fill_attribute = drawableContainerElement.Attribute("fill"); if (fill_attribute != null) { Fill = SvgPaint.Parse(fill_attribute.Value); } XAttribute stroke_attribute = drawableContainerElement.Attribute("stroke"); if (stroke_attribute != null) { Stroke = SvgPaint.Parse(stroke_attribute.Value); } XAttribute stroke_width_attribute = drawableContainerElement.Attribute("stroke-width"); if (stroke_width_attribute != null) { StrokeWidth = SvgLength.Parse(stroke_width_attribute.Value); } XAttribute stroke_linecap_attribute = drawableContainerElement.Attribute("stroke-linecap"); if (stroke_linecap_attribute != null) { switch (stroke_linecap_attribute.Value) { case "butt": StrokeLinecap = SvgStrokeLinecap.Butt; break; case "round": StrokeLinecap = SvgStrokeLinecap.Round; break; case "square": StrokeLinecap = SvgStrokeLinecap.Square; break; case "inherit": StrokeLinecap = SvgStrokeLinecap.Inherit; break; default: throw new NotImplementedException(); } } XAttribute stroke_linejoin_attribute = drawableContainerElement.Attribute("stroke-linejoin"); if (stroke_linejoin_attribute != null) { switch (stroke_linejoin_attribute.Value) { case "miter": StrokeLinejoin = SvgStrokeLinejoin.Miter; break; case "round": StrokeLinejoin = SvgStrokeLinejoin.Round; break; case "bevel": StrokeLinejoin = SvgStrokeLinejoin.Bevel; break; case "inherit": StrokeLinejoin = SvgStrokeLinejoin.Inherit; break; default: throw new NotSupportedException(); } } XAttribute stroke_miterlimit_attribute = drawableContainerElement.Attribute("stroke-miterlimit"); if (stroke_miterlimit_attribute != null) { if (stroke_miterlimit_attribute.Value == "inherit") { StrokeMiterlimit = Double.NaN; } else { double miterlimit = Double.Parse(stroke_miterlimit_attribute.Value, CultureInfo.InvariantCulture.NumberFormat); //if(miterlimit < 1) //throw new NotSupportedException("A miterlimit less than 1 is not supported."); StrokeMiterlimit = miterlimit; } } XAttribute stroke_dasharray_attribute = drawableContainerElement.Attribute("stroke-dasharray"); if (stroke_dasharray_attribute != null) { if (stroke_dasharray_attribute.Value == "none") { StrokeDasharray = null; } else if (stroke_dasharray_attribute.Value == "inherit") { StrokeDasharray = new SvgLength[0]; } else { List <SvgLength> lengths = new List <SvgLength>(); var lengthTokens = stroke_dasharray_attribute.Value.Replace(";", "") .Trim() .Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string length in lengthTokens) { lengths.Add(SvgLength.Parse(length)); } if (lengths.Count % 2 == 1) { StrokeDasharray = new SvgLength[lengths.Count * 2]; for (int i = 0; i < lengths.Count - 1; ++i) { StrokeDasharray[i] = lengths[i]; StrokeDasharray[i + lengths.Count] = lengths[i]; } } else { StrokeDasharray = lengths.ToArray(); } } } XAttribute stroke_dashoffset_attribute = drawableContainerElement.Attribute("stroke-dashoffset"); if (stroke_dashoffset_attribute != null) { StrokeDashoffset = SvgLength.Parse(stroke_dashoffset_attribute.Value); } XAttribute fill_rule_attribute = drawableContainerElement.Attribute("fill-rule"); if (fill_rule_attribute != null) { switch (fill_rule_attribute.Value) { case "nonzero": FillRule = SvgFillRule.Nonzero; break; case "evenodd": FillRule = SvgFillRule.Evenodd; break; case "inherit": FillRule = SvgFillRule.Inherit; break; default: throw new NotImplementedException(); } } // color, color-interpolation, color-rendering XAttribute width_attribute = drawableContainerElement.Attribute("width"); if (width_attribute != null) { Width = SvgLength.Parse(width_attribute.Value); } XAttribute height_attribute = drawableContainerElement.Attribute("height"); if (height_attribute != null) { Height = SvgLength.Parse(height_attribute.Value); } XAttribute preserveAspectRatio_attribute = drawableContainerElement.Attribute("preserveAspectRatio"); if (preserveAspectRatio_attribute != null) { switch (preserveAspectRatio_attribute.Value) { case "none": if (Width != null && Height != null) { var scaleTransform = new SvgScaleTransform( Width.ToDouble() / ViewBox.Value.Width, Height.ToDouble() / ViewBox.Value.Height); Width.ToDouble(); if (Transform == null) { Transform = scaleTransform; } else { Transform = new SvgTransformGroup(new[] { Transform, scaleTransform }); } } break; } } // overflow }
//========================================================================== public SvgMetadataElement(SvgDocument document, SvgBaseElement parent, XElement metadataElement) : base(document, parent, metadataElement) { }
//========================================================================== 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)); } } } } }
//========================================================================== public SvgGElement(SvgDocument document, SvgBaseElement parent, XElement gElement) : base(document, parent, gElement) { // ... }
//========================================================================== public SvgDrawableContainerBaseElement(SvgDocument document, SvgBaseElement parent, XElement drawableContainerElement) : base(document, parent, drawableContainerElement) { XAttribute opacity_attribute = drawableContainerElement.Attribute("opacity"); if (opacity_attribute != null) { Opacity = SvgLength.Parse(opacity_attribute.Value); } XAttribute transform_attribute = drawableContainerElement.Attribute("transform"); if (transform_attribute != null) { Transform = SvgTransform.Parse(transform_attribute.Value); } XAttribute clip_attribute = drawableContainerElement.Attribute("clip-path"); if (clip_attribute != null) { ClipPath = SvgURL.Parse(clip_attribute.Value); } XAttribute filter_attribute = drawableContainerElement.Attribute("filter"); if (filter_attribute != null) { Filter = SvgURL.Parse(filter_attribute.Value); } XAttribute mask_attribute = drawableContainerElement.Attribute("mask"); if (mask_attribute != null) { Mask = SvgURL.Parse(mask_attribute.Value); } XAttribute display_attribute = drawableContainerElement.Attribute("display"); if (display_attribute != null) { switch (display_attribute.Value) { case "inline": Display = SvgDisplay.Inline; break; case "block": Display = SvgDisplay.Block; break; case "list-item": Display = SvgDisplay.ListItem; break; case "run-in": Display = SvgDisplay.RunIn; break; case "compact": Display = SvgDisplay.Compact; break; case "marker": Display = SvgDisplay.Marker; break; case "table": Display = SvgDisplay.Table; break; case "inline-table": Display = SvgDisplay.InlineTable; break; case "table-row-group": Display = SvgDisplay.TableRowGroup; break; case "table-header-group": Display = SvgDisplay.TableHeaderGroup; break; case "table-footer-group": Display = SvgDisplay.TableFooterGroup; break; case "table-row": Display = SvgDisplay.TableRow; break; case "table-column-group": Display = SvgDisplay.TableColumnGroup; break; case "table-column": Display = SvgDisplay.TableColumn; break; case "table-cell": Display = SvgDisplay.TableCell; break; case "table-caption": Display = SvgDisplay.TableCaption; break; case "none": Display = SvgDisplay.None; break; default: throw new NotImplementedException(); } } }
//========================================================================== public SvgTextElement(SvgDocument document, SvgBaseElement parent, XElement svgElement) : base(document, parent, svgElement) { // ... }
//========================================================================== public SvgDrawableBaseElement(SvgDocument document, SvgBaseElement parent, XElement drawableBaseElement) : base(document, parent, drawableBaseElement) { XAttribute opacity_attribute = drawableBaseElement.Attribute("opacity"); SvgLength.TryUpdate(ref Opacity, opacity_attribute?.Value); XAttribute fill_opacity_attribute = drawableBaseElement.Attribute("fill-opacity"); SvgLength.TryUpdate(ref FillOpacity, fill_opacity_attribute?.Value); XAttribute stroke_opacity_attribute = drawableBaseElement.Attribute("stroke-opacity"); SvgLength.TryUpdate(ref StrokeOpacity, stroke_opacity_attribute?.Value); XAttribute transform_attribute = drawableBaseElement.Attribute("transform"); if (transform_attribute != null) { Transform = SvgTransform.Parse(transform_attribute.Value); } XAttribute fill_attribute = drawableBaseElement.Attribute("fill"); if (fill_attribute != null) { Fill = SvgPaint.Parse(fill_attribute.Value); } XAttribute stroke_attribute = drawableBaseElement.Attribute("stroke"); if (stroke_attribute != null) { Stroke = SvgPaint.Parse(stroke_attribute.Value); } XAttribute stroke_width_attribute = drawableBaseElement.Attribute("stroke-width"); SvgLength.TryUpdate(ref StrokeWidth, stroke_width_attribute?.Value); XAttribute stroke_linecap_attribute = drawableBaseElement.Attribute("stroke-linecap"); if (stroke_linecap_attribute != null) { switch (stroke_linecap_attribute.Value) { case "butt": StrokeLinecap = SvgStrokeLinecap.Butt; break; case "round": StrokeLinecap = SvgStrokeLinecap.Round; break; case "square": StrokeLinecap = SvgStrokeLinecap.Square; break; case "inherit": StrokeLinecap = SvgStrokeLinecap.Inherit; break; default: throw new NotImplementedException(); } } XAttribute stroke_linejoin_attribute = drawableBaseElement.Attribute("stroke-linejoin"); if (stroke_linejoin_attribute != null) { switch (stroke_linejoin_attribute.Value) { case "miter": StrokeLinejoin = SvgStrokeLinejoin.Miter; break; case "round": StrokeLinejoin = SvgStrokeLinejoin.Round; break; case "bevel": StrokeLinejoin = SvgStrokeLinejoin.Bevel; break; case "inherit": StrokeLinejoin = SvgStrokeLinejoin.Inherit; break; default: throw new NotSupportedException(); } } XAttribute stroke_miterlimit_attribute = drawableBaseElement.Attribute("stroke-miterlimit"); if (stroke_miterlimit_attribute != null) { if (stroke_miterlimit_attribute.Value == "inherit") { StrokeMiterlimit = Double.NaN; } else { double miterlimit = Double.Parse(stroke_miterlimit_attribute.Value, CultureInfo.InvariantCulture.NumberFormat); //if(miterlimit < 1) //throw new NotSupportedException("A miterlimit less than 1 is not supported."); StrokeMiterlimit = miterlimit; } } XAttribute stroke_dasharray_attribute = drawableBaseElement.Attribute("stroke-dasharray"); if (stroke_dasharray_attribute != null) { if (stroke_dasharray_attribute.Value == "none") { StrokeDasharray = null; } else if (stroke_dasharray_attribute.Value == "inherit") { StrokeDasharray = new SvgLength[0]; } else { List <SvgLength> lengths = new List <SvgLength>(); var lengthTokens = stroke_dasharray_attribute.Value.Replace(";", "") .Trim() .Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string length in lengthTokens) { lengths.Add(SvgLength.Parse(length)); } if (lengths.Count % 2 == 1) { StrokeDasharray = new SvgLength[lengths.Count * 2]; for (int i = 0; i < lengths.Count - 1; ++i) { StrokeDasharray[i] = lengths[i]; StrokeDasharray[i + lengths.Count] = lengths[i]; } } else { StrokeDasharray = lengths.ToArray(); } } } XAttribute stroke_dashoffset_attribute = drawableBaseElement.Attribute("stroke-dashoffset"); SvgLength.TryUpdate(ref StrokeDashoffset, stroke_dashoffset_attribute?.Value); XAttribute clip_attribute = drawableBaseElement.Attribute("clip-path"); if (clip_attribute != null) { string clip_path = clip_attribute.Value.Trim(); if (clip_path.StartsWith("url")) { clip_path = clip_path.Substring(3).Trim(); if (clip_path.StartsWith("(") && clip_path.EndsWith(")")) { clip_path = clip_path.Substring(1, clip_path.Length - 2).Trim(); if (clip_path.StartsWith("#")) { ClipPath = clip_path.Substring(1); } } } } XAttribute filter_attribute = drawableBaseElement.Attribute("filter"); if (filter_attribute != null) { string filter = filter_attribute.Value.Trim(); if (filter.StartsWith("url")) { filter = filter.Substring(3).Trim(); if (filter.StartsWith("(") && filter.EndsWith(")")) { filter = filter.Substring(1, filter.Length - 2).Trim(); if (filter.StartsWith("#")) { Filter = filter.Substring(1); } } } } XAttribute mask_attribute = drawableBaseElement.Attribute("mask"); if (mask_attribute != null) { string mask = mask_attribute.Value.Trim(); if (mask.StartsWith("url")) { mask = mask.Substring(3).Trim(); if (mask.StartsWith("(") && mask.EndsWith(")")) { mask = mask.Substring(1, mask.Length - 2).Trim(); if (mask.StartsWith("#")) { Mask = mask.Substring(1); } } } } XAttribute display_attribute = drawableBaseElement.Attribute("display"); if (display_attribute != null) { switch (display_attribute.Value) { case "inline": Display = SvgDisplay.Inline; break; case "block": Display = SvgDisplay.Block; break; case "list-item": Display = SvgDisplay.ListItem; break; case "run-in": Display = SvgDisplay.RunIn; break; case "compact": Display = SvgDisplay.Compact; break; case "marker": Display = SvgDisplay.Marker; break; case "table": Display = SvgDisplay.Table; break; case "inline-table": Display = SvgDisplay.InlineTable; break; case "table-row-group": Display = SvgDisplay.TableRowGroup; break; case "table-header-group": Display = SvgDisplay.TableHeaderGroup; break; case "table-footer-group": Display = SvgDisplay.TableFooterGroup; break; case "table-row": Display = SvgDisplay.TableRow; break; case "table-column-group": Display = SvgDisplay.TableColumnGroup; break; case "table-column": Display = SvgDisplay.TableColumn; break; case "table-cell": Display = SvgDisplay.TableCell; break; case "table-caption": Display = SvgDisplay.TableCaption; break; case "none": Display = SvgDisplay.None; break; default: throw new NotImplementedException(); } } XAttribute fill_rule_attribute = drawableBaseElement.Attribute("fill-rule"); if (fill_rule_attribute != null) { switch (fill_rule_attribute.Value) { case "nonzero": FillRule = SvgFillRule.Nonzero; break; case "evenodd": FillRule = SvgFillRule.Evenodd; break; case "inherit": FillRule = SvgFillRule.Inherit; break; default: throw new NotImplementedException(); } } // color, color-interpolation, color-rendering // viewBox attribute // preserveAspectRatio attribute // overflow foreach (XElement element in from element in drawableBaseElement.Elements() where element.Name.NamespaceName == "http://www.w3.org/2000/svg" select element) { switch (element.Name.LocalName) { default: throw new NotImplementedException(String.Format("Unhandled element: {0}", element)); } } }
//========================================================================== public SvgFilterEffectBaseElement(SvgDocument document, SvgBaseElement parent, XElement filterEffectElement) : base(document, parent, filterEffectElement) { // ... }
//========================================================================== public SvgDefsElement(SvgDocument document, SvgBaseElement parent, XElement defsElement) : base(document, parent, defsElement) { // ... }
//========================================================================== public SvgFlowRegionElement(SvgDocument document, SvgBaseElement parent, XElement flowRegionElement) : base(document, parent, flowRegionElement) { // ... }
//========================================================================== public SvgUseElement(SvgDocument document, SvgBaseElement parent, XElement useElement) : base(document, parent, useElement) { // ... }
//========================================================================== public SvgForeignObjectElement(SvgDocument document, SvgBaseElement parent, XElement foreignObjectElement) : base(document, parent, foreignObjectElement) { // ... }
//========================================================================== public SvgStyleElement(SvgDocument document, SvgBaseElement parent, XElement styleElement) : base(document, parent, styleElement) { // ... }
//========================================================================== public SvgContainerBaseElement(SvgDocument document, SvgBaseElement parent, XElement containerElement) : base(document, parent, containerElement) { foreach (XElement element in from element in containerElement.Elements() where element.Name.NamespaceName == "http://www.w3.org/2000/svg" select element) { switch (element.Name.LocalName) { case "svg": Children.Add(new SvgSVGElement(document, this, element)); break; case "g": Children.Add(new SvgGElement(document, this, element)); break; case "defs": Children.Add(new SvgDefsElement(document, this, element)); break; case "symbol": Children.Add(new SvgSymbolElement(document, this, element)); break; case "clipPath": Children.Add(new SvgClipPathElement(document, this, element)); break; case "mask": Children.Add(new SvgMaskElement(document, this, element)); break; case "pattern": Children.Add(new SvgPatternElement(document, this, element)); break; case "marker": Children.Add(new SvgMarkerElement(document, this, element)); break; case "a": Children.Add(new SvgAElement(document, this, element)); break; case "switch": Children.Add(new SvgSwitchElement(document, this, element)); break; case "path": Children.Add(new SvgPathElement(document, this, element)); break; case "text": Children.Add(new SvgTextElement(document, this, element)); break; case "rect": Children.Add(new SvgRectElement(document, this, element)); break; case "circle": Children.Add(new SvgCircleElement(document, this, element)); break; case "ellipse": Children.Add(new SvgEllipseElement(document, this, element)); break; case "line": Children.Add(new SvgLineElement(document, this, element)); break; case "polyline": Children.Add(new SvgPolylineElement(document, this, element)); break; case "polygon": Children.Add(new SvgPolygonElement(document, this, element)); break; case "image": Children.Add(new SvgImageElement(document, this, element)); break; case "use": Children.Add(new SvgUseElement(document, this, element)); break; case "linearGradient": Children.Add(new SvgLinearGradientElement(document, this, element)); break; case "radialGradient": Children.Add(new SvgRadialGradientElement(document, this, element)); break; case "filter": Children.Add(new SvgFilterElement(document, this, element)); break; case "metadata": Children.Add(new SvgMetadataElement(document, this, element)); break; case "flowRoot": Children.Add(new SvgFlowRootElement(document, this, element)); break; case "flowRegion": Children.Add(new SvgFlowRegionElement(document, this, element)); break; case "flowPara": Children.Add(new SvgFlowParaElement(document, this, element)); break; case "flowSpan": Children.Add(new SvgFlowSpanElement(document, this, element)); break; case "tspan": Children.Add(new SvgTSpanElement(document, this, element)); break; case "foreignObject": Children.Add(new SvgForeignObjectElement(document, this, element)); break; case "style": Children.Add(new SvgStyleElement(document, this, element)); break; default: //throw new NotImplementedException(String.Format("Unhandled svg element: {0}", element)); Debug.WriteLine("Unhandled svg element: {0}", element); break; } } }
//========================================================================== public SvgAElement(SvgDocument document, SvgBaseElement parent, XElement aElement) : base(document, parent, aElement) { // ... }
//========================================================================== public SvgFEColorMatrixElement(SvgDocument document, SvgBaseElement parent, XElement feColorMatrixElement) : base(document, parent, feColorMatrixElement) { // ... }
//========================================================================== public SvgClipPathElement(SvgDocument document, SvgBaseElement parent, XElement clipPathElement) : base(document, parent, clipPathElement) { // ... }
//========================================================================== public SvgFEBlendElement(SvgDocument document, SvgBaseElement parent, XElement feBlendElement) : base(document, parent, feBlendElement) { // ... }
//========================================================================== public SvgFlowParaElement(SvgDocument document, SvgBaseElement parent, XElement flowParaElement) : base(document, parent, flowParaElement) { }
//========================================================================== public SvgDrawableBaseElement(SvgDocument document, SvgBaseElement parent, XElement drawableBaseElement) : base(document, parent, drawableBaseElement) { XAttribute opacity_attribute = drawableBaseElement.Attribute("opacity"); if(opacity_attribute != null) Opacity = SvgLength.Parse(opacity_attribute.Value); XAttribute fill_opacity_attribute = drawableBaseElement.Attribute("fill-opacity"); if(fill_opacity_attribute != null) FillOpacity = SvgLength.Parse(fill_opacity_attribute.Value); XAttribute stroke_opacity_attribute = drawableBaseElement.Attribute("stroke-opacity"); if(stroke_opacity_attribute != null) StrokeOpacity = SvgLength.Parse(stroke_opacity_attribute.Value); XAttribute transform_attribute = drawableBaseElement.Attribute("transform"); if(transform_attribute != null) Transform = SvgTransform.Parse(transform_attribute.Value); XAttribute fill_attribute = drawableBaseElement.Attribute("fill"); if(fill_attribute != null) Fill = SvgPaint.Parse(fill_attribute.Value); XAttribute stroke_attribute = drawableBaseElement.Attribute("stroke"); if(stroke_attribute != null) Stroke = SvgPaint.Parse(stroke_attribute.Value); XAttribute stroke_width_attribute = drawableBaseElement.Attribute("stroke-width"); if(stroke_width_attribute != null) StrokeWidth = SvgLength.Parse(stroke_width_attribute.Value); XAttribute stroke_linecap_attribute = drawableBaseElement.Attribute("stroke-linecap"); if(stroke_linecap_attribute != null) switch(stroke_linecap_attribute.Value) { case "butt": StrokeLinecap = SvgStrokeLinecap.Butt; break; case "round": StrokeLinecap = SvgStrokeLinecap.Round; break; case "square": StrokeLinecap = SvgStrokeLinecap.Square; break; case "inherit": StrokeLinecap = SvgStrokeLinecap.Inherit; break; default: throw new NotImplementedException(); } XAttribute stroke_linejoin_attribute = drawableBaseElement.Attribute("stroke-linejoin"); if(stroke_linejoin_attribute != null) switch(stroke_linejoin_attribute.Value) { case "miter": StrokeLinejoin = SvgStrokeLinejoin.Miter; break; case "round": StrokeLinejoin = SvgStrokeLinejoin.Round; break; case "bevel": StrokeLinejoin = SvgStrokeLinejoin.Bevel; break; case "inherit": StrokeLinejoin = SvgStrokeLinejoin.Inherit; break; default: throw new NotSupportedException(); } XAttribute stroke_miterlimit_attribute = drawableBaseElement.Attribute("stroke-miterlimit"); if(stroke_miterlimit_attribute != null) { if(stroke_miterlimit_attribute.Value == "inherit") StrokeMiterlimit = Double.NaN; else { double miterlimit = Double.Parse(stroke_miterlimit_attribute.Value, CultureInfo.InvariantCulture.NumberFormat); //if(miterlimit < 1) //throw new NotSupportedException("A miterlimit less than 1 is not supported."); StrokeMiterlimit = miterlimit; } } XAttribute stroke_dasharray_attribute = drawableBaseElement.Attribute("stroke-dasharray"); if(stroke_dasharray_attribute != null) { if(stroke_dasharray_attribute.Value == "none") StrokeDasharray = null; else if(stroke_dasharray_attribute.Value == "inherit") StrokeDasharray = new SvgLength[0]; else { List<SvgLength> lengths = new List<SvgLength>(); foreach(string length in stroke_dasharray_attribute.Value.Split(',')) lengths.Add(SvgLength.Parse(length)); if(lengths.Count % 2 == 1) { StrokeDasharray = new SvgLength[lengths.Count * 2]; for(int i = 0; i < lengths.Count - 1; ++i) { StrokeDasharray[i] = lengths[i]; StrokeDasharray[i + lengths.Count] = lengths[i]; } } else StrokeDasharray = lengths.ToArray(); } } XAttribute stroke_dashoffset_attribute = drawableBaseElement.Attribute("stroke-dashoffset"); if(stroke_dashoffset_attribute != null) StrokeDashoffset = SvgLength.Parse(stroke_dashoffset_attribute.Value); XAttribute clip_attribute = drawableBaseElement.Attribute("clip-path"); if(clip_attribute != null) { string clip_path = clip_attribute.Value.Trim(); if(clip_path.StartsWith("url")) { clip_path = clip_path.Substring(3).Trim(); if(clip_path.StartsWith("(") && clip_path.EndsWith(")")) { clip_path = clip_path.Substring(1, clip_path.Length - 2).Trim(); if(clip_path.StartsWith("#")) ClipPath = clip_path.Substring(1); } } } XAttribute filter_attribute = drawableBaseElement.Attribute("filter"); if(filter_attribute != null) { string filter = filter_attribute.Value.Trim(); if(filter.StartsWith("url")) { filter = filter.Substring(3).Trim(); if(filter.StartsWith("(") && filter.EndsWith(")")) { filter = filter.Substring(1, filter.Length - 2).Trim(); if(filter.StartsWith("#")) Filter = filter.Substring(1); } } } XAttribute mask_attribute = drawableBaseElement.Attribute("mask"); if(mask_attribute != null) { string mask = mask_attribute.Value.Trim(); if(mask.StartsWith("url")) { mask = mask.Substring(3).Trim(); if(mask.StartsWith("(") && mask.EndsWith(")")) { mask = mask.Substring(1, mask.Length - 2).Trim(); if(mask.StartsWith("#")) Mask = mask.Substring(1); } } } XAttribute display_attribute = drawableBaseElement.Attribute("display"); if(display_attribute != null) switch(display_attribute.Value) { case "inline": Display = SvgDisplay.Inline; break; case "block": Display = SvgDisplay.Block; break; case "list-item": Display = SvgDisplay.ListItem; break; case "run-in": Display = SvgDisplay.RunIn; break; case "compact": Display = SvgDisplay.Compact; break; case "marker": Display = SvgDisplay.Marker; break; case "table": Display = SvgDisplay.Table; break; case "inline-table": Display = SvgDisplay.InlineTable; break; case "table-row-group": Display = SvgDisplay.TableRowGroup; break; case "table-header-group": Display = SvgDisplay.TableHeaderGroup; break; case "table-footer-group": Display = SvgDisplay.TableFooterGroup; break; case "table-row": Display = SvgDisplay.TableRow; break; case "table-column-group": Display = SvgDisplay.TableColumnGroup; break; case "table-column": Display = SvgDisplay.TableColumn; break; case "table-cell": Display = SvgDisplay.TableCell; break; case "table-caption": Display = SvgDisplay.TableCaption; break; case "none": Display = SvgDisplay.None; break; default: throw new NotImplementedException(); } XAttribute fill_rule_attribute = drawableBaseElement.Attribute("fill-rule"); if(fill_rule_attribute != null) switch(fill_rule_attribute.Value) { case "nonzero": FillRule = SvgFillRule.Nonzero; break; case "evenodd": FillRule = SvgFillRule.Evenodd; break; case "inherit": FillRule = SvgFillRule.Inherit; break; default: throw new NotImplementedException(); } // color, color-interpolation, color-rendering // viewBox attribute // preserveAspectRatio attribute // overflow foreach(XElement element in from element in drawableBaseElement.Elements() where element.Name.NamespaceName == "http://www.w3.org/2000/svg" select element) switch(element.Name.LocalName) { default: throw new NotImplementedException(String.Format("Unhandled element: {0}", element)); } }
//========================================================================== public SvgContainerBaseElement(SvgDocument document, SvgBaseElement parent, XElement containerElement) : base(document, parent, containerElement) { foreach(XElement element in from element in containerElement.Elements() where element.Name.NamespaceName == "http://www.w3.org/2000/svg" select element) switch(element.Name.LocalName) { case "svg": Children.Add(new SvgSVGElement(document, this, element)); break; case "g": Children.Add(new SvgGElement(document, this, element)); break; case "defs": Children.Add(new SvgDefsElement(document, this, element)); break; case "symbol": Children.Add(new SvgSymbolElement(document, this, element)); break; case "clipPath": Children.Add(new SvgClipPathElement(document, this, element)); break; case "mask": Children.Add(new SvgMaskElement(document, this, element)); break; case "pattern": Children.Add(new SvgPatternElement(document, this, element)); break; case "marker": Children.Add(new SvgMarkerElement(document, this, element)); break; case "a": Children.Add(new SvgAElement(document, this, element)); break; case "switch": Children.Add(new SvgSwitchElement(document, this, element)); break; case "path": Children.Add(new SvgPathElement(document, this, element)); break; case "text": Children.Add(new SvgTextElement(document, this, element)); break; case "rect": Children.Add(new SvgRectElement(document, this, element)); break; case "circle": Children.Add(new SvgCircleElement(document, this, element)); break; case "ellipse": Children.Add(new SvgEllipseElement(document, this, element)); break; case "line": Children.Add(new SvgLineElement(document, this, element)); break; case "polyline": Children.Add(new SvgPolylineElement(document, this, element)); break; case "polygon": Children.Add(new SvgPolygonElement(document, this, element)); break; case "image": Children.Add(new SvgImageElement(document, this, element)); break; case "use": Children.Add(new SvgUseElement(document, this, element)); break; case "linearGradient": Children.Add(new SvgLinearGradientElement(document, this, element)); break; case "radialGradient": Children.Add(new SvgRadialGradientElement(document, this, element)); break; case "filter": Children.Add(new SvgFilterElement(document, this, element)); break; case "metadata": Children.Add(new SvgMetadataElement(document, this, element)); break; case "flowRoot": Children.Add(new SvgFlowRootElement(document, this, element)); break; case "flowRegion": Children.Add(new SvgFlowRegionElement(document, this, element)); break; case "flowPara": Children.Add(new SvgFlowParaElement(document, this, element)); break; case "flowSpan": Children.Add(new SvgFlowSpanElement(document, this, element)); break; case "tspan": Children.Add(new SvgTSpanElement(document, this, element)); break; case "foreignObject": Children.Add(new SvgForeignObjectElement(document, this, element)); break; case "style": Children.Add(new SvgStyleElement(document, this, element)); break; default: throw new NotImplementedException(String.Format("Unhandled element: {0}", element)); } }
//========================================================================== public SvgMarkerElement(SvgDocument document, SvgBaseElement parent, XElement markerElement) : base(document, parent, markerElement) { // ... }
//========================================================================== public SvgTSpanElement(SvgDocument document, SvgBaseElement parent, XElement svgElement) : base(document, parent, svgElement) { // ... }