Exemplo n.º 1
0
        //==========================================================================
        public SvgRectElement(SvgDocument document, SvgBaseElement parent, XElement rectElement)
            : base(document, parent, rectElement)
        {
            var x_attribute = rectElement.Attribute("x");

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

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

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

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

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

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

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

            var rx_attribute = rectElement.Attribute("rx");

            if (rx_attribute != null)
            {
                CornerRadiusX = SvgCoordinate.Parse(rx_attribute.Value);
            }

            var ry_attribute = rectElement.Attribute("ry");

            if (ry_attribute != null)
            {
                CornerRadiusY = SvgCoordinate.Parse(ry_attribute.Value);
            }
        }
Exemplo n.º 2
0
        //==========================================================================
        public SvgRadialGradientElement(SvgDocument document, SvgBaseElement parent, XElement radialGradientElement)
            : base(document, parent, radialGradientElement)
        {
            var cx_attribute = radialGradientElement.Attribute("cx");

            if (cx_attribute != null)
            {
                CX = SvgCoordinate.Parse(cx_attribute.Value);
            }

            var cy_attribute = radialGradientElement.Attribute("cy");

            if (cy_attribute != null)
            {
                CY = SvgCoordinate.Parse(cy_attribute.Value);
            }

            var r_attribute = radialGradientElement.Attribute("r");

            if (r_attribute != null)
            {
                R = SvgCoordinate.Parse(r_attribute.Value);
            }

            var fx_attribute = radialGradientElement.Attribute("fx");

            if (fx_attribute != null)
            {
                FX = SvgCoordinate.Parse(fx_attribute.Value);
            }

            var fy_attribute = radialGradientElement.Attribute("fy");

            if (fy_attribute != null)
            {
                FY = SvgCoordinate.Parse(fy_attribute.Value);
            }
        }
Exemplo n.º 3
0
        //==========================================================================
        public SvgCircleElement(SvgDocument document, SvgBaseElement parent, XElement circleElement)
            : base(document, parent, circleElement)
        {
            var cx_attribute = circleElement.Attribute("cx");

            if (cx_attribute != null)
            {
                CenterX = SvgCoordinate.Parse(cx_attribute.Value);
            }

            var cy_attribute = circleElement.Attribute("cy");

            if (cy_attribute != null)
            {
                CenterY = SvgCoordinate.Parse(cy_attribute.Value);
            }

            var r_attribute = circleElement.Attribute("r");

            if (r_attribute != null)
            {
                Radius = SvgLength.Parse(r_attribute.Value);
            }
        }
Exemplo n.º 4
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}");
                        }
                    }
                }
            }
        }