示例#1
0
            public LineTo(char command, ShapeUtil.StringSplitter value) : base(command)
            {
                if (char.ToLower(command) == 'h')
                {
                    this.PositionType = eType.Horizontal;
                    double v = value.ReadNextValue();
                    this.Points = new Point[] { new Point(v, 0) };
                    return;
                }
                if (char.ToLower(command) == 'v')
                {
                    this.PositionType = eType.Vertical;
                    double v = value.ReadNextValue();
                    this.Points = new Point[] { new Point(0, v) };
                    return;
                }

                this.PositionType = eType.Point;
                List <Point> list = new List <Point>();

                while (value.More)
                {
                    Point p = value.ReadNextPoint();
                    list.Add(p);
                }
                this.Points = list.ToArray();
            }
示例#2
0
        public static Transform ParseTransform(string value)
        {
            string type = ExtractUntil(value, '(');
            string v1   = ExtractBetween(value, '(', ')');

            ShapeUtil.StringSplitter split  = new ShapeUtil.StringSplitter(v1);
            List <double>            values = new List <double>();

            while (split.More)
            {
                values.Add(split.ReadNextValue());
            }
            if (type == SVGTags.sTranslate)
            {
                return(new TranslateTransform(values[0], values[1]));
            }
            if (type == SVGTags.sMatrix)
            {
                return(Transform.Parse(v1));
            }
            if (type == SVGTags.sScale)
            {
                return(new ScaleTransform(values[0], values[1]));
            }
            if (type == SVGTags.sRotate)
            {
                return(new RotateTransform(values[0], values[1], values[2]));
            }

            return(null);
        }
示例#3
0
            public EllipticalArcTo(char command, ShapeUtil.StringSplitter value) : base(command)
            {
                this.RX           = value.ReadNextValue();
                this.RY           = value.ReadNextValue();
                this.AxisRotation = value.ReadNextValue();
                double arcflag = value.ReadNextValue();

                this.LargeArc = (arcflag > 0);
                double sweepflag = value.ReadNextValue();

                this.Clockwise = (sweepflag > 0);
                this.X         = value.ReadNextValue();
                this.Y         = value.ReadNextValue();
            }
示例#4
0
 public MoveTo(char command, ShapeUtil.StringSplitter value) : base(command)
 {
     this.Point = value.ReadNextPoint();
 }
示例#5
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));
            }
        }
示例#6
0
 public CurveTo(char command, ShapeUtil.StringSplitter value, Point ctrlPoint1) : base(command)
 {
     this.CtrlPoint1 = ctrlPoint1;
     this.CtrlPoint2 = value.ReadNextPoint();
     this.Point      = value.ReadNextPoint();
 }
示例#7
0
        private static Transform ParseTransformInternal(string value)
        {
            string type = ExtractUntil(value, '(').TrimStart(',');
            string v1   = ExtractBetween(value, '(', ')');

            ShapeUtil.StringSplitter split  = new ShapeUtil.StringSplitter(v1);
            List <double>            values = new List <double>();

            while (split.More)
            {
                values.Add(split.ReadNextValue());
            }
            if (type == SVGTags.sTranslate)
            {
                if (values.Count == 1)
                {
                    return(new TranslateTransform(values[0], 0));
                }
                else
                {
                    return(new TranslateTransform(values[0], values[1]));
                }
            }
            if (type == SVGTags.sMatrix)
            {
                return(Transform.Parse(v1));
            }
            if (type == SVGTags.sScale)
            {
                if (values.Count == 1)
                {
                    return(new ScaleTransform(values[0], values[0]));
                }
                else
                {
                    return(new ScaleTransform(values[0], values[1]));
                }
            }
            if (type == SVGTags.sSkewX)
            {
                return(new SkewTransform(values[0], 0));
            }
            if (type == SVGTags.sSkewY)
            {
                return(new SkewTransform(0, values[0]));
            }
            if (type == SVGTags.sRotate)
            {
                if (values.Count == 1)
                {
                    return(new RotateTransform(values[0], 0, 0));
                }
                if (values.Count == 2)
                {
                    return(new RotateTransform(values[0], values[1], 0));
                }
                return(new RotateTransform(values[0], values[1], values[2]));
            }

            return(null);
        }
示例#8
0
 public QuadraticCurveTo(char command, ShapeUtil.StringSplitter value) : base(command)
 {
     this.CtrlPoint1 = value.ReadNextPoint();
     this.Point      = value.ReadNextPoint();
 }