Пример #1
0
        public static LinearGradient ConvertLinearGradient(XElement svgGradient, List <string> warnings)
        {
            const string typeName = "linearGradient";

            if (svgGradient.Name != Namespace.Svg + typeName)
            {
                throw new ArgumentException("Argument is not the expected <" + typeName + "> SVG element");
            }

            var hrefElement = GetGradientHrefElement(svgGradient, warnings);

            float x1 = 0, y1 = 0, x2 = 1, y2 = 0;

            if (GetAttribute("x1", svgGradient, hrefElement) is XAttribute x1Attribute)
            {
                var f = x1Attribute.Value.ToPathOffset();
                if (!float.IsNaN(f))
                {
                    x1 = f;
                }
                else
                {
                    warnings.AddWarning("Could not parse x1 parameter of <" + typeName + " id='" + svgGradient.Attribute("id")?.Value + "'>");
                }
            }
            if (GetAttribute("y1", svgGradient, hrefElement) is XAttribute y1Attribute)
            {
                var f = y1Attribute.Value.ToPathOffset();
                if (!float.IsNaN(f))
                {
                    y1 = f;
                }
                else
                {
                    warnings.AddWarning("Could not parse y1 parameter of <" + typeName + " id='" + svgGradient.Attribute("id")?.Value + "'>");
                }
            }
            if (GetAttribute("x2", svgGradient, hrefElement) is XAttribute x2Attribute)
            {
                var f = x2Attribute.Value.ToPathOffset();
                if (!float.IsNaN(f))
                {
                    x2 = f;
                }
                else
                {
                    warnings.AddWarning("Could not parse x2 parameter of <" + typeName + " id='" + svgGradient.Attribute("id")?.Value + "'>");
                }
            }
            if (GetAttribute("y2", svgGradient, hrefElement) is XAttribute y2Attribute)
            {
                var f = y2Attribute.Value.ToPathOffset();
                if (!float.IsNaN(f))
                {
                    y2 = f;
                }
                else
                {
                    warnings.AddWarning("Could not parse y2 parameter of <" + typeName + " id='" + svgGradient.Attribute("id")?.Value + "'>");
                }
            }

            if (x1 == x2 && y1 == y2)
            {
                warnings.AddWarning("Ignoring SVG element because start [" + x1 + "," + y1 + "] and end [" + x2 + "," + y2 + "] points are the same for <" + typeName + " id=\"" + svgGradient.Attribute("id")?.Value + "\".");
                return(null);
            }

            var avGradient = new LinearGradient();

            avGradient.SetAndroidAttributeValue("startX", x1);
            avGradient.SetAndroidAttributeValue("startY", y1);
            avGradient.SetAndroidAttributeValue("endX", x2);
            avGradient.SetAndroidAttributeValue("endY", y2);
            SetCommonGradientAttributes(svgGradient, hrefElement, avGradient, warnings);



            return(avGradient);
        }