コード例 #1
0
        public string ProcessCanvas()
        {
            string    formatData = "";
            Converter converter;

            foreach (Shape shape in Canvas.Children)
            {
                switch (shape.DependencyObjectType.Name)
                {
                case "Line": { converter = new LineConverter(Format); break; }

                case "Ellipse": { converter = new EllipseConverter(Format); break; }

                case "Rectangle": { converter = new RectangleConverter(Format); break; }

                case "Polygon": { converter = new PolygonConverter(Format); break; }

                default: { converter = null; break; }
                }
                if (converter != null)
                {
                    formatData += "shape : " + converter.ShapeToFormat(shape);
                }
            }
            return(formatData);
        }
コード例 #2
0
        public override void Load()
        {
            XDocument svgParsed = XDocument.Parse(File.ReadAllText(Path));

            if (svgParsed.Root.Name != "svg")
            {
                return;
            }
            double    ratioX = 1.0, ratioY = 1.0; //для масштабирования значений в фигурах
            Converter converter;

            //Descendants возвращает коллекцию всех тегов в файле
            foreach (XElement e in svgParsed.Descendants())
            {
                switch (e.Name.ToString())
                {
                case "svg":
                {
                    converter = null;
                    foreach (XAttribute k in e.Attributes())
                    {
                        if (k.Name == "height")
                        {
                            Canvas.Height = stringToDouble(k.Value); continue;
                        }
                        if (k.Name == "width")
                        {
                            Canvas.Width = stringToDouble(k.Value); continue;
                        }
                        if (k.Name == "viewBox")
                        {
                            var split = k.Value.Split(' ').Select(stringToDouble).ToArray();
                            ratioX = (Canvas.Width) / split[2];
                            ratioY = (Canvas.Height) / split[3];
                            continue;
                        }
                        //Console.WriteLine(k.Name + " = " + k.Value);
                    }
                    break;
                }

                case "line": { converter = new LineConverter(Format); break; }

                case "ellipse": { converter = new EllipseConverter(Format); break; }

                case "rect": { converter = new RectangleConverter(Format); break; }

                case "polygon": { converter = new PolygonConverter(Format); break; }

                default: { converter = null; break; }
                }
                if (converter != null)
                {
                    ConvertTarget target = new ConvertTarget(e, new Point(ratioX, ratioY));
                    Canvas.Children.Add(converter.FormatToShape(target));
                }
            }
        }
コード例 #3
0
        public override void Load()
        {
            string[] vgfData = File.ReadAllText(Path).Split(':');
            Canvas.Width  = Convert.ToDouble(vgfData[0].Split(' ')[0]);
            Canvas.Height = Convert.ToDouble(vgfData[0].Split(' ')[1]);

            if (vgfData[1].Length < 1)
            {
                return;                        //если в файле нет фигур
            }
            Converter converter;

            foreach (var e in vgfData[1].Split(';'))
            {
                if (e.Length == 0)
                {
                    continue;                //фиктивный элемент массива после последней ; (результат split)
                }
                string[] shapeArray = e.Split(' ');
                switch (shapeArray[0])
                {
                case "Line": { converter = new LineConverter(Format); break; }

                case "Ellipse": { converter = new EllipseConverter(Format); break; }

                case "Rectangle": { converter = new RectangleConverter(Format); break; }

                case "Polygon": { converter = new PolygonConverter(Format); break; }

                default: { converter = null; break; }
                }
                if (converter != null)
                {
                    ConvertTarget target = new ConvertTarget(shapeArray);
                    Canvas.Children.Add(converter.FormatToShape(target));
                }
            }
        }