예제 #1
0
 public Boolean Load(String strFilePath)
 {
     try
     {
         m_strFilePath = strFilePath;
         m_entities.Clear();
         XmlDocument doc = new XmlDocument();
         doc.Load(strFilePath);
         XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
         nsmgr.AddNamespace("svg", "http://www.w3.org/2000/svg");
         XmlNode node = doc.DocumentElement.SelectSingleNode("//svg:svg", nsmgr);
         XmlAttributeCollection attributes = node.Attributes;
         //the document might contain a viewbox, if it does then we use that for the document size
         XmlNode viewBox = attributes.GetNamedItem("viewBox");
         if (viewBox != null)
         {
             String[] slVieWbox = viewBox.Value.Split(' ');
             if (slVieWbox.Length > 3)
             {
                 m_dWidth  = (float)Convert.ToDouble(slVieWbox[2]);
                 m_dHeight = (float)Convert.ToDouble(slVieWbox[3]);
             }
         }
         else
         {
             //otherwise look for a wide and height value
             XmlNode width = attributes.GetNamedItem("width");
             if (width != null)
             {
                 m_dWidth = (float)Convert.ToDouble(width.Value);
             }
             XmlNode height = attributes.GetNamedItem("height");
             if (height != null)
             {
                 m_dHeight = (float)Convert.ToDouble(height.Value);
             }
         }
         //parse the rest of the document
         for (int a = 0; a < node.ChildNodes.Count; a++)
         {
             XmlNode   child  = node.ChildNodes[a];
             svgEntity entity = new svgEntity();
             if (entity.Parse(child))
             {
                 m_entities.Add(entity);
             }
         }
         m_nLayerCount   = GetLayerCount();
         m_nCurrentLayer = 0;
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
     }
     return(false);
 }
예제 #2
0
 public virtual Boolean Parse(XmlNode node)
 {
     try
     {
         m_strType = node.Name;
         if (node.Attributes != null)
         {
             m_attributes = node.Attributes;
         }
         m_strTransform = GetAttribute("transform");
         String strStyle = GetAttribute("style");
         m_style.Parse(strStyle);
         if (m_style.m_bVisible == false)
         {
             return(false);
         }
         if (node.ChildNodes != null)
         {
             for (int a = 0; a < node.ChildNodes.Count; a++)
             {
                 XmlNode child = node.ChildNodes[a];
                 if (child.Name == "path")
                 {
                     svgPath path = new svgPath();
                     path.setParent(this);
                     m_entities.Add(path);
                     path.Parse(child);
                 }
                 else if (child.Name == "rect")
                 {
                     svgRect rect = new svgRect();
                     rect.setParent(this);
                     m_entities.Add(rect);
                     rect.Parse(child);
                 }
                 else if (child.Name == "circle")
                 {
                     svgCircle circle = new svgCircle();
                     circle.setParent(this);
                     m_entities.Add(circle);
                     circle.Parse(child);
                 }
                 else if (child.Name == "ellipse")
                 {
                     svgEllipse ellipse = new svgEllipse();
                     ellipse.setParent(this);
                     m_entities.Add(ellipse);
                     ellipse.Parse(child);
                 }
                 else
                 {
                     //groups get processed here
                     svgEntity entity = new svgEntity();
                     entity.setParent(this);
                     m_entities.Add(entity);
                     entity.Parse(child);
                 }
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
     }
     return(false);
 }
예제 #3
0
 public void setParent(svgEntity parent)
 {
     m_parent = parent;
 }