コード例 #1
0
ファイル: Group.cs プロジェクト: soapgu/SVGImage
        public static Shape AddToList(SVG svg, List <Shape> list, XmlNode childnode, Shape parent)
        {
            if (childnode.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            Shape retVal = null;

            var nodeName = GetNodeName(childnode);

            if (nodeName == null)
            {
                return(null);
            }
            if (nodeName == SVGTags.sStyle)
            {
                StyleParser.ParseStyle(svg, childnode.InnerText);
            }
            else if (nodeName == SVGTags.sShapeRect)
            {
                retVal = new RectangleShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sFilter)
            {
                retVal = new Filter(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sFeGaussianBlur)
            {
                retVal = new FilterFeGaussianBlur(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sShapeCircle)
            {
                retVal = new CircleShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapeEllipse)
            {
                retVal = new EllipseShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapeLine)
            {
                retVal = new LineShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapePolyline)
            {
                retVal = new PolylineShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapePolygon)
            {
                retVal = new PolygonShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapePath)
            {
                retVal = new PathShape(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sClipPath)
            {
                retVal = new Clip(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sShapeGroup)
            {
                retVal = new Group(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sSwitch)
            {
                retVal = new Group(svg, childnode, parent)
                {
                    IsSwitch = true
                }
            }
            ;
            else if (nodeName == SVGTags.sShapeUse)
            {
                retVal = new UseShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sShapeImage)
            {
                retVal = new ImageShape(svg, childnode);
            }
            else if (nodeName == SVGTags.sAnimate)
            {
                retVal = new Animate(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sAnimateColor)
            {
                retVal = new AnimateColor(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sAnimateMotion)
            {
                retVal = new AnimateMotion(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sAnimateTransform)
            {
                retVal = new AnimateTransform(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sText)
            {
                retVal = new TextShape(svg, childnode, parent);
            }
            else if (nodeName == SVGTags.sLinearGradient)
            {
                svg.PaintServers.Create(svg, childnode);
                return(null);
            }
            else if (nodeName == SVGTags.sRadialGradient)
            {
                svg.PaintServers.Create(svg, childnode);
                return(null);
            }
            else if (nodeName == SVGTags.sDefinitions)
            {
                ReadDefs(svg, list, childnode);
                return(null);
            }
            else if (nodeName == SVGTags.sSymbol)
            {
                retVal = new Group(svg, childnode, parent);
            }

            if (retVal != null)
            {
                list.Add(retVal);
                if (retVal.Id.Length > 0)
                {
                    svg.AddShape(retVal.Id, retVal);
                }
            }

            if (nodeName == SVGTags.sSymbol)
            {
                return(null);
            }

            return(retVal);
        }
コード例 #2
0
        public static Shape AddToList(SVG svg, List <Shape> list, XmlNode childnode, Shape parent)
        {
            if (childnode.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            Shape retVal = null;

            if (childnode.Name == SVGTags.sStyle)
            {
                var match = _regexStyle.Match(childnode.InnerText);
                while (match.Success)
                {
                    var name  = match.Groups[1].Value.Trim();
                    var value = match.Groups[2].Value;
                    svg.m_styles.Add(name, new List <XmlAttribute>());
                    foreach (ShapeUtil.Attribute styleitem in XmlUtil.SplitStyle(svg, value))
                    {
                        svg.m_styles[name].Add(new XmlUtil.StyleItem(childnode, styleitem.Name, styleitem.Value));
                    }
                    match = match.NextMatch();
                }
            }
            else if (childnode.Name == SVGTags.sShapeRect)
            {
                retVal = new RectangleShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sFilter)
            {
                retVal = new Filter(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sFeGaussianBlur)
            {
                retVal = new FilterFeGaussianBlur(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sShapeCircle)
            {
                retVal = new CircleShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapeEllipse)
            {
                retVal = new EllipseShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapeLine)
            {
                retVal = new LineShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapePolyline)
            {
                retVal = new PolylineShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapePolygon)
            {
                retVal = new PolygonShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapePath)
            {
                retVal = new PathShape(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sClipPath)
            {
                retVal = new Clip(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sShapeGroup || childnode.Name == SVGTags.sSwitch)
            {
                retVal = new Group(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sShapeUse)
            {
                retVal = new UseShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sShapeImage)
            {
                retVal = new ImageShape(svg, childnode);
            }
            else if (childnode.Name == SVGTags.sAnimate)
            {
                retVal = new Animate(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sAnimateColor)
            {
                retVal = new AnimateColor(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sAnimateMotion)
            {
                retVal = new AnimateMotion(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sAnimateTransform)
            {
                retVal = new AnimateTransform(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sText)
            {
                retVal = new TextShape(svg, childnode, parent);
            }
            else if (childnode.Name == SVGTags.sLinearGradient)
            {
                svg.PaintServers.Create(childnode);
                return(null);
            }
            else if (childnode.Name == SVGTags.sRadialGradient)
            {
                svg.PaintServers.Create(childnode);
                return(null);
            }
            else if (childnode.Name == SVGTags.sDefinitions)
            {
                ReadDefs(svg, list, childnode);
                return(null);
            }

            if (retVal != null)
            {
                list.Add(retVal);
                if (retVal.Id.Length > 0)
                {
                    svg.AddShape(retVal.Id, retVal);
                }
            }

            return(retVal);
        }
コード例 #3
0
        public MotionPathAnimation(CommonTimeNode commonTimeNode, int slideIndex, SlideSize SlideSizes)
        {
            this.SlideSizes = SlideSizes;
            InitialState    = 4;
            timingType      = commonTimeNode.NodeType;
            Type            = AnimationTypes.MotionPath;
            AnimateMotion motion = null;

            foreach (Object xmlEl in commonTimeNode.Descendants())
            {
                if (xmlEl.GetType().Equals(typeof(AnimateMotion)))
                {
                    motion = (AnimateMotion)xmlEl;
                }
            }
            if (motion == null)
            {
                return;
            }
            String path = motion.Path.Value;

            String[] parts = path.Split();
            motionPath = new List <PathPart>();
            int  indexPart = -1;
            bool isX       = true;

            foreach (string part in parts)
            {
                if ("".Equals(part) || "E".Equals(part))  //We add our End tag
                {
                    continue;
                }
                Double coords = 0.0;
                if (!Double.TryParse(part, NumberStyles.Float, CultureInfo.InvariantCulture, out coords))
                {
                    isX = true;
                    if (indexPart >= 0)
                    {  //FIX FOR POINTS WITH 3 COORDINATES UNTIL WE KNOW WHAT THEY ARE.
                        List <PathPoint> previousPartPoints = motionPath[indexPart].points;
                        if (previousPartPoints[previousPartPoints.Count - 1].Y.CompareTo(0) == 0)
                        {
                            previousPartPoints.Remove(previousPartPoints[previousPartPoints.Count - 1]);
                        }
                    }

                    indexPart++;
                    motionPath.Add(new PathPart());
                    motionPath[indexPart].typeCharacter = part;
                }
                else if (isX)
                {
                    coords = coords * MultiplierX();
                    PathPoint newPoint = new PathPoint();
                    newPoint.X = coords;
                    motionPath[indexPart].points.Add(newPoint);   // We have a new point
                    isX = !isX;
                }
                else
                {
                    coords = coords * MultiplierY();
                    motionPath[indexPart].points[motionPath[indexPart].points.Count - 1].Y = coords;  //Set Y for the last point
                    isX = !isX;
                }
            }


            FixAnimationTimings(motion.CommonBehavior, slideIndex);
            generateAdditionDataString(motionPath);
        }