Esempio n. 1
0
        internal static List <Shape> Parse(SVG svg, XmlNode node)
        {
            var vb = node.Attributes.GetNamedItem("viewBox");

            if (vb != null)
            {
                var cord = vb.Value.Split(' ');
                var cult = CultureInfo.InvariantCulture;
                svg.ViewBox = new Rect(double.Parse(cord[0], cult), double.Parse(cord[1], cult), double.Parse(cord[2], cult), double.Parse(cord[3], cult));
            }

            svg.Size = new Size(XmlUtil.AttrValue(node, "width", 300), XmlUtil.AttrValue(node, "height", 150));

            var lstElements = new List <Shape>();

            if (node == null || (node.Name != SVGTags.sSvg && node.Name != SVGTags.sPattern))
            {
                throw new FormatException("Not a valide SVG node");
            }
            foreach (XmlNode childnode in node.ChildNodes)
            {
                Group.AddToList(svg, lstElements, childnode, null);
            }
            return(lstElements);
        }
Esempio n. 2
0
 public ClipArtElement(XmlNode node)
 {
     if (node == null)
     {
         this.Id = "<null>";
     }
     else
     {
         this.Id = XmlUtil.AttrValue(node, "id");
     }
 }
Esempio n. 3
0
 public TextShape(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent)
 {
     this.X    = XmlUtil.AttrValue(node, "x", 0);
     this.Y    = XmlUtil.AttrValue(node, "y", 0);
     this.Text = node.InnerText;
     this.GetTextStyle(svg);
     // check for tSpan tag
     if (node.InnerXml.IndexOf("<") >= 0)
     {
         this.TextSpan = this.ParseTSpan(svg, node.InnerXml);
     }
     //if (DefaultFill == null)
     //{
     //	DefaultFill = new Fill(svg);
     //	DefaultFill.PaintServerKey = svg.PaintServers.Parse("black");
     //}
     if (DefaultStroke == null)
     {
         DefaultStroke       = new Stroke(svg);
         DefaultStroke.Width = 0.1;
     }
 }
Esempio n. 4
0
        // http://apike.ca/prog_svg_paths.html
        public PathShape(SVG svg, XmlNode node) : base(svg, node)
        {
            if (DefaultFill == null)
            {
                DefaultFill       = new Fill(svg);
                DefaultFill.Color = svg.PaintServers.Parse("black");
            }


            this.ClosePath = false;
            string             path = XmlUtil.AttrValue(node, "d", string.Empty);
            CommandSplitter    cmd  = new CommandSplitter(path);
            string             commandstring;
            char               command;
            List <PathElement> elements = this.m_elements;

            while (true)
            {
                commandstring = cmd.ReadNext();
                if (commandstring.Length == 0)
                {
                    break;
                }
                ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
                if (command == 'm' || command == 'M')
                {
                    elements.Add(new MoveTo(command, split));
                    if (split.More)
                    {
                        elements.Add(new LineTo(command, split));
                    }
                    continue;
                }
                if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
                {
                    elements.Add(new LineTo(command, split));
                    continue;
                }
                if (command == 'c' || command == 'C')
                {
                    while (split.More)
                    {
                        elements.Add(new CurveTo(command, split));
                    }
                    continue;
                }
                if (command == 's' || command == 'S')
                {
                    while (split.More)
                    {
                        CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
                        System.Diagnostics.Debug.Assert(lastshape != null);
                        elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
                    }
                    continue;
                }
                if (command == 'a' || command == 'A')
                {
                    elements.Add(new EllipticalArcTo(command, split));
                    while (split.More)
                    {
                        elements.Add(new EllipticalArcTo(command, split));
                    }
                    continue;
                }
                if (command == 'z' || command == 'Z')
                {
                    this.ClosePath = true;
                    continue;
                }

                // extended format moveto or lineto can contain multiple points which should be translated into lineto
                PathElement lastitem = elements[elements.Count - 1];
                if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
                {
                    //Point p = Point.Parse(s);
                    //elements.Add(new LineTo(p));
                    continue;
                }


                System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring));
            }
        }
Esempio n. 5
0
        // http://apike.ca/prog_svg_paths.html
        public PathShape(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent)
        {
            if (DefaultFill == null)
            {
                DefaultFill = new Fill(svg);
                DefaultFill.PaintServerKey = svg.PaintServers.Parse("black");
            }

            this.ClosePath = false;
            string path = XmlUtil.AttrValue(node, "d", string.Empty);

            this.Data = path;

            /*
             * CommandSplitter cmd = new CommandSplitter(path);
             * string commandstring;
             * char command;
             * List<PathElement> elements = this.m_elements;
             * while (true)
             * {
             *  commandstring = cmd.ReadNext();
             *  if (commandstring.Length == 0)
             *      break;
             *  ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
             *  if (command == 'm' || command == 'M')
             *  {
             *      elements.Add(new MoveTo(command, split));
             *      if (split.More)
             *          elements.Add(new LineTo(command, split));
             *      continue;
             *  }
             *  if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
             *  {
             *      elements.Add(new LineTo(command, split));
             *      continue;
             *  }
             *  if (command == 'c' || command == 'C')
             *  {
             *      while (split.More)
             *          elements.Add(new CurveTo(command, split));
             *      continue;
             *  }
             *  if (command == 'q' || command == 'Q')
             *  {
             *      while (split.More)
             *          elements.Add(new QuadraticCurveTo(command, split));
             *      continue;
             *  }
             *  if (command == 's' || command == 'S')
             *  {
             *      while (split.More)
             *      {
             *          CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
             *          System.Diagnostics.Debug.Assert(lastshape != null);
             *          elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
             *      }
             *      continue;
             *  }
             *  if (command == 'a' || command == 'A')
             *  {
             *      elements.Add(new EllipticalArcTo(command, split));
             *      while (split.More)
             *          elements.Add(new EllipticalArcTo(command, split));
             *      continue;
             *  }
             *  if (command == 'z' || command == 'Z')
             *  {
             *      this.ClosePath = true;
             *      continue;
             *  }
             *
             *  // extended format moveto or lineto can contain multiple points which should be translated into lineto
             *  PathElement lastitem = elements[elements.Count - 1];
             *  if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
             *  {
             *      //Point p = Point.Parse(s);
             *      //elements.Add(new LineTo(p));
             *      continue;
             *  }
             *
             *
             *  System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring));
             * }
             */
        }