Exemple #1
0
 private static void RecLoadFromXML(SvgElement e, XmlDocument doc, XmlElement el)
 {
     e.ReadXmlElement(doc, el);
     foreach (XmlNode xmlNode in el.ChildNodes)
     {
         if (xmlNode.GetType() == typeof(XmlElement))
         {
             XmlElement xmlElement = (XmlElement)xmlNode;
             Type       type       = (Type)SvgFactory._elementNameDictionary[xmlElement.Name];
             SvgElement svgElement;
             if (type == null)
             {
                 svgElement = new SvgGenericElement(xmlElement.Name);
             }
             else
             {
                 svgElement = (SvgElement)type.GetConstructor(new Type[0]).Invoke(new object[0]);
             }
             e.AddChild(svgElement);
             SvgFactory.RecLoadFromXML(svgElement, doc, xmlElement);
         }
         else if (xmlNode.GetType() == typeof(XmlText))
         {
             XmlText  xmlText = (XmlText)xmlNode;
             TextNode ch      = new TextNode(xmlText.InnerText);
             e.AddChild(ch);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Used by LoadFromXML
        /// </summary>
        /// <param name="e"></param>
        /// <param name="doc"></param>
        /// <param name="el"></param>
        private static void RecLoadFromXML(SvgElement e, XmlDocument doc, XmlElement el)
        {
            e.ReadXmlElement(doc, el);

            foreach (XmlNode noddo in el.ChildNodes)
            {
                if (noddo.GetType() == typeof(XmlElement))
                {
                    var childXml = (XmlElement)noddo;

                    var t = (Type)_elementNameDictionary[childXml.Name];

                    SvgElement childSvg = null;

                    if (t == null)
                    {
                        childSvg = new SvgGenericElement(childXml.Name);
                    }
                    else
                    {
                        childSvg = (SvgElement)t.GetConstructor(new Type[0]).Invoke(new object[0]);
                    }

                    e.AddChild(childSvg);

                    RecLoadFromXML(childSvg, doc, childXml);
                }
                else if (noddo.GetType() == typeof(XmlText))
                {
                    var xt = (XmlText)noddo;

                    var tn = new TextNode(xt.InnerText);

                    e.AddChild(tn);
                }
            }
        }
Exemple #3
0
        public static SvgElement CloneElement(SvgElement el)
        {
            SvgElement svgElement = (SvgElement)el.GetType().GetConstructor(new Type[0]).Invoke(new object[0]);

            foreach (string attname in el.Attributes.Keys)
            {
                object obj = el[attname];
                if (typeof(ICloneable).IsInstanceOfType(obj))
                {
                    svgElement[attname] = ((ICloneable)obj).Clone();
                }
                else
                {
                    svgElement[attname] = obj;
                }
            }
            foreach (SvgElement el2 in el.Children)
            {
                svgElement.AddChild(SvgFactory.CloneElement(el2));
            }
            return(svgElement);
        }
Exemple #4
0
        /// <summary>
        /// Create a complete deep copy of the given tree of <c>SvgElement</c> objects.
        /// A new set of elements is created, and if the attributes are cloneable they are deep-copied too.
        /// Since strings and all SvgType classes are cloneable, the new tree is independant of the old.
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        public static SvgElement CloneElement(SvgElement el)
        {
            SvgElement clone = (SvgElement)el.GetType().GetConstructor(new System.Type[0]).Invoke(new object[0]);

            foreach (string key in el.Attributes.Keys)
            {
                object o = el[key];
                if (typeof(ICloneable).IsInstanceOfType(o))
                {
                    clone[key] = ((ICloneable)o).Clone();
                }
                else
                {
                    clone[key] = o;
                }
            }

            foreach (SvgElement ch in el.Children)
            {
                clone.AddChild(CloneElement(ch));
            }

            return(clone);
        }
Exemple #5
0
        /// <summary>
        /// Used by LoadFromXML
        /// </summary>
        /// <param name="e"></param>
        /// <param name="doc"></param>
        /// <param name="el"></param>
        private static void RecLoadFromXML(SvgElement e, XmlDocument doc, XmlElement el)
        {
            e.ReadXmlElement(doc, el);

            foreach(XmlNode noddo in el.ChildNodes)
            {
                if (noddo.GetType() == typeof(XmlElement))
                {
                    XmlElement childXml = (XmlElement)noddo;

                    Type t = (Type)_elementNameDictionary[childXml.Name];

                    SvgElement childSvg=null;

                    if (t == null)
                    {
                        childSvg = new SvgGenericElement(childXml.Name);
                    }
                    else
                    {
                        childSvg = (SvgElement)t.GetConstructor(new System.Type[0]).Invoke(new object[0]);
                    }

                    e.AddChild(childSvg);

                    RecLoadFromXML(childSvg, doc, childXml);
                }
                else if (noddo.GetType() == typeof(XmlText))
                {
                    XmlText xt = (XmlText)noddo;

                    TextNode tn = new TextNode(xt.InnerText);

                    e.AddChild(tn);
                }
            }
        }