Exemple #1
0
        /// <summary>
        /// Parse all graphic elements
        /// </summary>
        private GraphicGroup ParseGroup(XNamespace ns, XElement groupElement, Matrix matrix)
        {
            var group = new GraphicGroup();

            cssStyleCascade.PushStyles(groupElement);

            Matrix currentTransformationMatrix = matrix;

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

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

            Clipping.SetClipPath(group, currentTransformationMatrix, cssStyleCascade, globalDefinitions);
            group.Opacity = cssStyleCascade.GetDoubleFromTop("opacity", 1);

            var shapeParser = new ShapeParser();

            foreach (var element in groupElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "defs":
                case "style":
                    // already read, ignore
                    break;

                case "g":
                case "svg":
                {
                    var childGroup = ParseGroup(ns, element, currentTransformationMatrix);
                    group.Childreen.Add(childGroup);
                    break;
                }

                default:
                {
                    var shape = shapeParser.Parse(element, ns, currentTransformationMatrix, cssStyleCascade, globalDefinitions);

                    if (shape != null)
                    {
                        group.Childreen.Add(shape);
                    }
                    break;
                }
                }
            }

            cssStyleCascade.Pop();

            return(group);
        }
Exemple #2
0
        private GraphicVisual ParseElement(XElement element, Matrix matrix)
        {
            GraphicVisual graphicVisual = null;

            switch (element.Name.LocalName)
            {
            case "defs":
            case "style":
            {
                // already read, ignore
                break;
            }

            case "svg":
            {
                graphicVisual = ParseSVG(element, matrix, false);
                break;
            }

            case "g":
            {
                graphicVisual = ParseGContainer(element, matrix);
                break;
            }

            case "text":
            {
                graphicVisual = textParser.Parse(element, matrix);
                break;
            }

            case "use":
            {
                graphicVisual = ParseUseElement(element, matrix);
                break;
            }

            default:
            {
                graphicVisual = shapeParser.Parse(element, matrix);
                break;
            }
            }

            return(graphicVisual);
        }