//==========================================================================
 public SvgFlowRegionElement(SvgDocument document, SvgBaseElement parent, XElement flowRegionElement)
     : base(document, parent, flowRegionElement)
 {
     // ...
 }
Beispiel #2
0
 //==========================================================================
 public override Brush ToBrush(SvgBaseElement element) => new SolidColorBrush(Color.ToColor());
Beispiel #3
0
 //==========================================================================
 public SvgGElement(SvgDocument document, SvgBaseElement parent, XElement gElement)
     : base(document, parent, gElement)
 {
     // ...
 }
 //==========================================================================
 public SvgForeignObjectElement(SvgDocument document, SvgBaseElement parent, XElement foreignObjectElement)
     : base(document, parent, foreignObjectElement)
 {
     // ...
 }
 //==========================================================================
 public SvgMetadataElement(SvgDocument document, SvgBaseElement parent, XElement metadataElement)
     : base(document, parent, metadataElement)
 {
 }
        //==========================================================================
        public SvgContainerBaseElement(SvgDocument document, SvgBaseElement parent, XElement containerElement)
            : base(document, parent, containerElement)
        {
            foreach (var 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;

                case "title":
                    break;

                default:
                    throw new NotImplementedException($"Unhandled element: {element}");
                }
            }
        }
Beispiel #7
0
 //==========================================================================
 public SvgFEColorMatrixElement(SvgDocument document, SvgBaseElement parent, XElement feColorMatrixElement)
     : base(document, parent, feColorMatrixElement)
 {
     // ...
 }
        //==========================================================================
        public SvgDrawableContainerBaseElement(SvgDocument document, SvgBaseElement parent, XElement drawableContainerElement)
            : base(document, parent, drawableContainerElement)
        {
            var opacity_attribute = drawableContainerElement.Attribute("opacity");

            if (opacity_attribute != null)
            {
                Opacity = SvgLength.Parse(opacity_attribute.Value);
            }

            var transform_attribute = drawableContainerElement.Attribute("transform");

            if (transform_attribute != null)
            {
                Transform = SvgTransform.Parse(transform_attribute.Value);
            }

            var clip_attribute = drawableContainerElement.Attribute("clip-path");

            if (clip_attribute != null)
            {
                ClipPath = SvgURL.Parse(clip_attribute.Value);
            }

            var filter_attribute = drawableContainerElement.Attribute("filter");

            if (filter_attribute != null)
            {
                Filter = SvgURL.Parse(filter_attribute.Value);
            }

            var mask_attribute = drawableContainerElement.Attribute("mask");

            if (mask_attribute != null)
            {
                Mask = SvgURL.Parse(mask_attribute.Value);
            }

            var 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 SvgClipPathElement(SvgDocument document, SvgBaseElement parent, XElement clipPathElement)
     : base(document, parent, clipPathElement)
 {
     // ...
 }
Beispiel #10
0
 //==========================================================================
 public abstract Brush ToBrush(SvgBaseElement element);
 //==========================================================================
 public SvgFEBlendElement(SvgDocument document, SvgBaseElement parent, XElement feBlendElement)
     : base(document, parent, feBlendElement)
 {
     // ...
 }
        //==========================================================================
        public SvgDrawableBaseElement(SvgDocument document, SvgBaseElement parent, XElement drawableBaseElement)
            : base(document, parent, drawableBaseElement)
        {
            var opacity_attribute = drawableBaseElement.Attribute("opacity");

            if (opacity_attribute != null)
            {
                Opacity = SvgLength.Parse(opacity_attribute.Value);
            }

            var fill_opacity_attribute = drawableBaseElement.Attribute("fill-opacity");

            if (fill_opacity_attribute != null)
            {
                FillOpacity = SvgLength.Parse(fill_opacity_attribute.Value);
            }

            var stroke_opacity_attribute = drawableBaseElement.Attribute("stroke-opacity");

            if (stroke_opacity_attribute != null)
            {
                StrokeOpacity = SvgLength.Parse(stroke_opacity_attribute.Value);
            }

            var transform_attribute = drawableBaseElement.Attribute("transform");

            if (transform_attribute != null)
            {
                Transform = SvgTransform.Parse(transform_attribute.Value);
            }

            var fill_attribute = drawableBaseElement.Attribute("fill");

            if (fill_attribute != null)
            {
                Fill = SvgPaint.Parse(fill_attribute.Value);
            }

            var stroke_attribute = drawableBaseElement.Attribute("stroke");

            if (stroke_attribute != null)
            {
                Stroke = SvgPaint.Parse(stroke_attribute.Value);
            }

            var stroke_width_attribute = drawableBaseElement.Attribute("stroke-width");

            if (stroke_width_attribute != null)
            {
                StrokeWidth = SvgLength.Parse(stroke_width_attribute.Value);
            }

            var stroke_linecap_attribute = drawableBaseElement.Attribute("stroke-linecap");

            if (stroke_linecap_attribute != null)
            {
                StrokeLinecap = stroke_linecap_attribute.Value switch
                {
                    "butt" => SvgStrokeLinecap.Butt,
                    "round" => SvgStrokeLinecap.Round,
                    "square" => SvgStrokeLinecap.Square,
                    "inherit" => SvgStrokeLinecap.Inherit,
                    _ => throw new NotImplementedException()
                }
            }
            ;

            var stroke_linejoin_attribute = drawableBaseElement.Attribute("stroke-linejoin");

            if (stroke_linejoin_attribute != null)
            {
                StrokeLinejoin = stroke_linejoin_attribute.Value switch
                {
                    "miter" => SvgStrokeLinejoin.Miter,
                    "round" => SvgStrokeLinejoin.Round,
                    "bevel" => SvgStrokeLinejoin.Bevel,
                    "inherit" => SvgStrokeLinejoin.Inherit,
                    _ => throw new NotSupportedException()
                }
            }
            ;

            var stroke_miterlimit_attribute = drawableBaseElement.Attribute("stroke-miterlimit");

            if (stroke_miterlimit_attribute != null)
            {
                if (stroke_miterlimit_attribute.Value == "inherit")
                {
                    StrokeMiterlimit = double.NaN;
                }
                else
                {
                    var 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;
                }
            }

            var 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 = Array.Empty <SvgLength>();
                }
                else
                {
                    var lengths = stroke_dasharray_attribute.Value.Split(',').Select(SvgLength.Parse).ToList();

                    if (lengths.Count % 2 == 1)
                    {
                        StrokeDasharray = new SvgLength[lengths.Count * 2];
                        for (var i = 0; i < lengths.Count - 1; ++i)
                        {
                            StrokeDasharray[i] = lengths[i];
                            StrokeDasharray[i + lengths.Count] = lengths[i];
                        }
                    }
                    else
                    {
                        StrokeDasharray = lengths.ToArray();
                    }
                }
            }

            var stroke_dashoffset_attribute = drawableBaseElement.Attribute("stroke-dashoffset");

            if (stroke_dashoffset_attribute != null)
            {
                StrokeDashoffset = SvgLength.Parse(stroke_dashoffset_attribute.Value);
            }

            var clip_attribute = drawableBaseElement.Attribute("clip-path");
            var clip_path      = clip_attribute?.Value.Trim();

            if (clip_path?.StartsWith("url") == true)
            {
                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);
                    }
                }
            }

            var filter_attribute = drawableBaseElement.Attribute("filter");
            var filter           = filter_attribute?.Value.Trim();

            if (filter?.StartsWith("url") == true)
            {
                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);
                    }
                }
            }

            var mask_attribute = drawableBaseElement.Attribute("mask");
            var mask           = mask_attribute?.Value.Trim();

            if (mask?.StartsWith("url") == true)
            {
                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);
                    }
                }
            }

            var 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();
                }
            }

            var fill_rule_attribute = drawableBaseElement.Attribute("fill-rule");

            if (fill_rule_attribute != null)
            {
                FillRule = fill_rule_attribute.Value switch
                {
                    "nonzero" => SvgFillRule.Nonzero,
                    "evenodd" => SvgFillRule.Evenodd,
                    "inherit" => SvgFillRule.Inherit,
                    _ => throw new NotImplementedException()
                }
            }
            ;

            // color, color-interpolation, color-rendering

            // viewBox attribute
            // preserveAspectRatio attribute

            // overflow


            foreach (var 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($"Unhandled element: {element}");
                }
            }
        }
Beispiel #13
0
 //==========================================================================
 public SvgStyleElement(SvgDocument document, SvgBaseElement parent, XElement styleElement)
     : base(document, parent, styleElement)
 {
     // ...
 }
Beispiel #14
0
 //==========================================================================
 public SvgDefsElement(SvgDocument document, SvgBaseElement parent, XElement defsElement)
     : base(document, parent, defsElement)
 {
     // ...
 }
Beispiel #15
0
 //==========================================================================
 public SvgTextElement(SvgDocument document, SvgBaseElement parent, XElement svgElement)
     : base(document, parent, svgElement)
 {
     // ...
 }
Beispiel #16
0
 //==========================================================================
 public SvgUseElement(SvgDocument document, SvgBaseElement parent, XElement useElement)
     : base(document, parent, useElement)
 {
     // ...
 }
Beispiel #17
0
 //==========================================================================
 public SvgAElement(SvgDocument document, SvgBaseElement parent, XElement aElement)
     : base(document, parent, aElement)
 {
     // ...
 }
 //==========================================================================
 public SvgMarkerElement(SvgDocument document, SvgBaseElement parent, XElement markerElement)
     : base(document, parent, markerElement)
 {
     // ...
 }
Beispiel #19
0
        //==========================================================================
        public SvgImageElement(SvgDocument document, SvgBaseElement parent, XElement imageElement)
            : base(document, parent, imageElement)
        {
            var x_attribute = imageElement.Attribute("x");

            if (x_attribute != null)
            {
                X = SvgCoordinate.Parse(x_attribute.Value);
            }

            var y_attribute = imageElement.Attribute("y");

            if (y_attribute != null)
            {
                Y = SvgCoordinate.Parse(y_attribute.Value);
            }

            var width_attribute = imageElement.Attribute("width");

            if (width_attribute != null)
            {
                Width = SvgLength.Parse(width_attribute.Value);
            }

            var height_attribute = imageElement.Attribute("height");

            if (height_attribute != null)
            {
                Height = SvgLength.Parse(height_attribute.Value);
            }

            var href_attribute = imageElement.Attribute(XName.Get("href", "http://www.w3.org/1999/xlink"));

            if (href_attribute != null)
            {
                var reference = href_attribute.Value.TrimStart();
                if (reference.StartsWith("data:"))
                {
                    reference = reference.Substring(5).TrimStart();
                    var index = reference.IndexOf(";");
                    if (index > -1)
                    {
                        var type = reference.Substring(0, index).Trim();
                        reference = reference.Substring(index + 1);

                        index = reference.IndexOf(",");
                        var 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($"Unsupported encoding: {encoding}");
                        }

                        var type_tokens = type.Split('/');
                        if (type_tokens.Length != 2)
                        {
                            throw new NotSupportedException($"Unsupported type: {type}");
                        }

                        type_tokens[0] = type_tokens[0].Trim();
                        if (type_tokens[0] != "image")
                        {
                            throw new NotSupportedException($"Unsupported type: {type}");
                        }

                        switch (type_tokens[1].Trim())
                        {
                        case "jpeg":
                            DataType = "jpeg";
                            break;

                        case "png":
                            DataType = "png";
                            break;

                        default:
                            throw new NotSupportedException($"Unsupported type: {type}");
                        }
                    }
                }
            }
        }
Beispiel #20
0
        //==========================================================================
        public SvgGradientBaseElement(SvgDocument document, SvgBaseElement parent, XElement gradientElement)
            : base(document, parent, gradientElement)
        {
            var 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($"gradientUnits value '{gradient_units_attribute.Value}' is no supported");
                }
            }

            var gradient_transform_attribute = gradientElement.Attribute("gradientTransform");

            if (gradient_transform_attribute != null)
            {
                Transform = SvgTransform.Parse(gradient_transform_attribute.Value);
            }

            var 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 (var 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($"Unhandled element: {element}");
                }
            }
        }