Ejemplo n.º 1
0
        /// <summary>
        /// Parse an SVG document fragment
        /// </summary>
        private GraphicGroup ParseSVG(XElement element, Matrix matrix, bool isTopLevelSvg)
        {
            cssStyleCascade.PushStyles(element);

            var(newViewBoxPushOnStack, viewBoxMatrix) = GetViewBoxMatrix(element, isTopLevelSvg);
            matrix = viewBoxMatrix * matrix;

            var elementTransformationMatrix = cssStyleCascade.GetTransformMatrixFromTop();

            elementTransformationMatrix = elementTransformationMatrix * matrix;

            var group = ParseChildren(element, elementTransformationMatrix);

            group.Opacity = cssStyleCascade.GetNumberPercentFromTop("opacity", 1);
            clipping.SetClipPath(group, elementTransformationMatrix);

            if (newViewBoxPushOnStack)
            {
                cssStyleCascade.PopViewBox();
            }

            cssStyleCascade.Pop();
            return(group);
        }
Ejemplo 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);
        }