Ejemplo n.º 1
0
        public static void AddPath(XElement svgElement, Group avGroup, List <string> warnings)
        {
            const string typeName = "path";

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

            var clipGroup = ClipConverter.ConvertClipPathAttribute(svgElement, avGroup, warnings);
            var avPath    = new Path();

            CommonAttributes.ProcessAttributes(svgElement, avPath, null, warnings);

            if (clipGroup != avGroup)
            {
                CommonAttributes.SetTransforms(svgElement, clipGroup, warnings);
                clipGroup.Add(avPath);
            }
            else
            {
                CommonAttributes.SetTransforms(svgElement, avPath, warnings);
                avGroup.Add(avPath);
            }
        }
Ejemplo n.º 2
0
        public static void AddEllipse(XElement svgElement, Group avGroup, List <string> warnings)
        {
            if (ConvertEllipseElementToPathData(svgElement, warnings) is string pathData)
            {
                var clipGroup        = ClipConverter.ConvertClipPathAttribute(svgElement, avGroup, warnings);
                var avPath           = new Path();
                var ignoreAttributes = new List <string> {
                    "cx", "cy", "rx", "ry"
                };
                CommonAttributes.ProcessAttributes(svgElement, avPath, ignoreAttributes, warnings);
                avPath.SetAndroidAttributeValue("pathData", pathData);

                if (clipGroup != avGroup)
                {
                    CommonAttributes.SetTransforms(svgElement, clipGroup, warnings);
                    clipGroup.Add(avPath);
                }
                else
                {
                    CommonAttributes.SetTransforms(svgElement, avPath, warnings);
                    avGroup.Add(avPath);
                }
            }
        }
Ejemplo n.º 3
0
        public static AndroidVector.Group AddClipPathElement(this XElement svgElement, AndroidVector.Group avGroup, List <string> warnings)
        {
            string typeName = svgElement.Name.LocalName;

            avGroup = ClipConverter.ConvertClipPathAttribute(svgElement, avGroup, warnings);
            CommonAttributes.ProcessAttributes(svgElement, avGroup, null, warnings);
            var avClip = new AndroidVector.ClipPath();

            foreach (var child in svgElement.Elements())
            {
                if (child.Name == Namespace.Svg + "use")
                {
                    float tx = 0, ty = 0;
                    if (child.Attribute("x") is XAttribute xAttribute)
                    {
                        AttributeExtensions.TryGetValueInPx(xAttribute, out tx);
                    }
                    if (child.Attribute("y") is XAttribute yAttribute)
                    {
                        AttributeExtensions.TryGetValueInPx(yAttribute, out ty);
                    }
                    if (tx != 0 || ty != 0)
                    {
                        avGroup.SvgTransforms.Add(Matrix.CreateTranslate(tx, ty));
                    }

                    if (child.Attribute(Namespace.xlinkNs + "href") is XAttribute hrefAttribute)
                    {
                        if (hrefAttribute.Value.StartsWith("#"))
                        {
                            var href = hrefAttribute.Value.Trim(new char[] { '#', ' ' });
                            var root = child.GetRoot();
                            if (root.Descendants().Where(e => e.Attribute("id")?.Value == href).FirstOrDefault() is XElement useElement)
                            {
                                if (useElement.Name == Namespace.Svg + "clipPath")
                                {
                                    avGroup = ClipConverter.ConvertClipPathAttribute(useElement, avGroup, warnings);
                                    CommonAttributes.ProcessAttributes(useElement, avGroup, new List <string> {
                                        "x", "y"
                                    }, warnings);
                                    AddClipPathElement(useElement, avGroup, warnings);
                                }
                                else if (GeometryConverter.ConvertElementToPathData(useElement, warnings) is string pathData)
                                {
                                    avClip.PathData += pathData;
                                    warnings.AddWarning("A union of two (or more) clippaths has been found.  If these clippaths overlap, you're likely not going to like the result.  Suggestion:  Use a vector image editor (like InkScape) to alter your union of clippaths to be one path, without crossing segments.");
                                }
                                else
                                {
                                    warnings.AddWarning("Ignoring <" + useElement.Name.LocalName + " id='" + useElement.Attribute("id")?.Value + "'> inside of <" + child.Name.LocalName + " id='" + child.Attribute("id")?.Value + "' xlink:href='" + hrefAttribute.Value + "' because could not find element referenced by xlink:href attribute.");
                                }
                            }
                            else
                            {
                                warnings.AddWarning("Ignoring <use id='" + svgElement.Attribute("id")?.Value + "' xlink:href='" + hrefAttribute.Value + "' because could not find element referenced by xlink:href attribute.");
                            }
                        }
                        else
                        {
                            warnings.AddWarning("Ignoring <use id='" + svgElement.Attribute("id")?.Value + "' xlink:href='" + hrefAttribute.Value + "' because xlink:href attribute is not a local anchor.");
                        }
                    }
                    else
                    {
                        warnings.AddWarning("Ignoring <use id='" + svgElement.Attribute("id")?.Value + "'> because cannot find xlink:href attribute.");
                    }
                    //    var tmpGroup = new AndroidVector.Group();
                }
                else if (GeometryConverter.ConvertElementToPathData(child, warnings) is string pathData)
                {
                    avClip.PathData += pathData;
                }
            }

            if (!string.IsNullOrWhiteSpace(avClip.PathData))
            {
                CommonAttributes.SetTransforms(svgElement, avClip, warnings);
                avGroup.Add(avClip);
            }

            return(avGroup);
        }