Exemplo n.º 1
0
        /// <summary>
        /// Parse a single SVG shape
        /// </summary>
        public GraphicVisual Parse(XElement shape,
                                   XNamespace svgNamespace,
                                   Matrix currentTransformationMatrix,
                                   CssStyleCascade cssStyleCascade,
                                   Dictionary <string, XElement> globalDefinitions)
        {
            GraphicVisual graphicVisual = null;

            cssStyleCascade.PushStyles(shape);

            var transform = cssStyleCascade.GetPropertyFromTop("transform");

            if (!string.IsNullOrEmpty(transform))
            {
                var transformMatrix = TransformMatrixParser.GetTransformMatrix(transform);
                currentTransformationMatrix = transformMatrix * currentTransformationMatrix;
            }

            var geometry = GeometryParser.Parse(shape, currentTransformationMatrix);

            if (geometry != null)
            {
                var graphicPath = new GraphicPath();
                graphicPath.Geometry = geometry;
                graphicVisual        = graphicPath;

                this.svgNamespace                = svgNamespace;
                this.globalDefinitions           = globalDefinitions;
                this.currentTransformationMatrix = currentTransformationMatrix;
                this.cssStyleCascade             = cssStyleCascade;

                SetFillAndStroke(shape, graphicPath);

                if (Clipping.IsClipPathSet(cssStyleCascade))
                {
                    // shapes don't support clipping, create a group around it
                    var group = new GraphicGroup();
                    graphicVisual = group;
                    group.Childreen.Add(graphicPath);

                    Clipping.SetClipPath(group, currentTransformationMatrix, cssStyleCascade, globalDefinitions);
                }

                cssStyleCascade.Pop();
            }

            return(graphicVisual);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse a single SVG shape
        /// </summary>
        public GraphicVisual Parse(XElement shape,
                                   Matrix currentTransformationMatrix)
        {
            GraphicVisual graphicVisual = null;

            cssStyleCascade.PushStyles(shape);

            var transformMatrix = cssStyleCascade.GetTransformMatrixFromTop();

            currentTransformationMatrix = transformMatrix * currentTransformationMatrix;

            var geometry = geometryParser.Parse(shape, currentTransformationMatrix);

            if (geometry != null)
            {
                var graphicPath = new GraphicPath();
                graphicPath.Geometry = geometry;
                graphicVisual        = graphicPath;

                brushParser.SetFillAndStroke(shape, graphicPath, currentTransformationMatrix);

                if (clipping.IsClipPathSet())
                {
                    // shapes don't support clipping, create a group around it
                    var group = new GraphicGroup();
                    graphicVisual = group;
                    group.Children.Add(graphicPath);

                    clipping.SetClipPath(group, currentTransformationMatrix);
                }
            }

            cssStyleCascade.Pop();

            return(graphicVisual);
        }