Esempio n. 1
0
        private void ParseChildNodes(SvgNode svgNode, XmlNodeList xmlNodeList)
        {
            foreach (XmlElement xmlNode in xmlNodeList)
            {
                SvgNode childNode = null;
                switch (xmlNode.LocalName)
                {
                case "defs":
                    childNode = ParseDefsElement(xmlNode);
                    break;

                case "g":
                    childNode = ParseGroupElement(xmlNode);
                    break;

                case "image":
                    childNode = ParseImageElement(xmlNode);
                    break;

                case "line":
                    childNode = ParseLineElement(xmlNode);
                    break;

                default:
                    childNode = ParseUnknownElement(xmlNode);
                    break;
                }

                if (childNode != null)
                {
                    svgNode.ChildNodes.Add(childNode);
                }
            }
        }
Esempio n. 2
0
        protected virtual void ReadAttributes(SvgNode svgNode, XmlElement xmlElement)
        {
            var attributes = svgNode.GetAttributes();

            if (attributes != null)
            {
                foreach (var svgAttribute in attributes)
                {
                    var xmlAttr = xmlElement.GetAttributeNode(svgAttribute.LocalName, svgAttribute.NamespaceUri);

                    if (xmlAttr == null &&
                        (svgAttribute.NamespaceUri == xmlElement.NamespaceURI ||
                         svgAttribute.NamespaceUri == XmlNamespace.Svg))
                    {
                        xmlAttr = xmlElement.GetAttributeNode(svgAttribute.LocalName);
                    }

                    if (xmlAttr != null)
                    {
                        svgAttribute.SetValue(xmlAttr.Value);
                    }
                }
            }

            if (_customAttributeReader != null)
            {
                _customAttributeReader.Read(svgNode, xmlElement);
            }
        }
Esempio n. 3
0
        protected virtual void WriteAttributes(SvgNode svgNode, XmlElement xmlElement)
        {
            var topParentNode = xmlElement;

            while (topParentNode.ParentNode as XmlElement != null)
            {
                topParentNode = topParentNode.ParentNode as XmlElement;
            }

            var prefix = xmlElement.GetPrefixOfNamespace(XmlNamespace.AurigmaSvg);

            if (string.IsNullOrEmpty(prefix))
            {
                topParentNode.SetAttribute("xmlns:aursvg", XmlNamespace.AurigmaSvg);
            }

            var type = _typeResolver.ResolveTypeAttribute(svgNode.GetType());

            if (!string.IsNullOrEmpty(type))
            {
                xmlElement.SetAttributeNode("type", XmlNamespace.AurigmaSvg).Value = type;
            }

            var attributes = svgNode.GetAttributes();

            if (attributes != null)
            {
                foreach (var attr in attributes)
                {
                    var value = attr.GetValue();
                    if (attr.DefaultValue != value && !string.IsNullOrEmpty(value))
                    {
                        XmlAttribute attrNode;
                        if (attr.NamespaceUri == XmlNamespace.Svg)
                        {
                            attrNode = _xmlDocument.CreateAttribute(attr.LocalName);
                        }
                        else
                        {
                            prefix = xmlElement.GetPrefixOfNamespace(attr.NamespaceUri);
                            if (string.IsNullOrEmpty(prefix))
                            {
                                prefix = _typeResolver.GetPrefix(attr.NamespaceUri);
                                if (!string.IsNullOrEmpty(prefix))
                                {
                                    topParentNode.SetAttribute("xmlns:" + prefix, attr.NamespaceUri);
                                }
                            }
                            attrNode = _xmlDocument.CreateAttribute(attr.LocalName, attr.NamespaceUri);
                        }
                        attrNode.Value = value;
                        xmlElement.Attributes.Append(attrNode);
                    }
                }
            }
        }
Esempio n. 4
0
        public virtual SvgNode CreateSvgNodeFromXml(XmlElement xmlElement)
        {
            SvgNode svgNode  = null;
            var     ns       = xmlElement.NamespaceURI;
            var     nodeName = xmlElement.LocalName;
            var     typeAttr = xmlElement.GetAttribute("type", XmlNamespace.AurigmaSvg);
            Type    type     = _typeResolver.ResolveType(ns, nodeName, typeAttr);

            if (type != null)
            {
                svgNode = (SvgNode)Activator.CreateInstance(type);
            }

            return(svgNode);
        }
Esempio n. 5
0
        public virtual void Read(SvgNode svgNode, XmlElement xmlElement)
        {
            var composite = svgNode as ISvgCompositeElement;

            if (composite != null)
            {
                composite.ReadContent(xmlElement, this);
            }
            else
            {
                ReadChildNodes(svgNode, xmlElement);
            }

            ReadAttributes(svgNode, xmlElement);
        }
Esempio n. 6
0
        public virtual void Write(SvgNode svgNode, XmlElement xmlElement)
        {
            WriteAttributes(svgNode, xmlElement);

            var composite = svgNode as ISvgCompositeElement;

            if (composite != null)
            {
                composite.WriteContent(xmlElement, this);
            }
            else
            {
                WriteChildNodes(svgNode, xmlElement);
            }
        }
Esempio n. 7
0
 protected virtual void ReadChildNodes(SvgNode svgNode, XmlElement xmlElement)
 {
     foreach (XmlNode childNode in xmlElement.ChildNodes)
     {
         var childElement = childNode as XmlElement;
         if (childElement != null)
         {
             var childSvgNode = CreateSvgNodeFromXml(childElement);
             if (childSvgNode != null)
             {
                 Read(childSvgNode, childElement);
                 svgNode.ChildNodes.Add(childSvgNode);
             }
         }
     }
 }
Esempio n. 8
0
        protected virtual void WriteChildNodes(SvgNode svgNode, XmlElement xmlElement)
        {
            var childNodes = svgNode.ChildNodes;

            if (childNodes != null)
            {
                foreach (var childNode in svgNode.ChildNodes)
                {
                    var childElement = CreateXmlElementFromSvg(childNode);
                    if (childElement != null)
                    {
                        xmlElement.AppendChild(childElement);
                        Write(childNode, childElement);
                    }
                }
            }
        }
Esempio n. 9
0
        public virtual XmlElement CreateXmlElementFromSvg(SvgNode svgNode)
        {
            var element = _xmlDocument.CreateElement(svgNode.LocalName, svgNode.NamespaceURI);

            return(element);
        }