Ejemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ShapeParser(CssStyleCascade cssStyleCascade,
                    BrushParser brushParser,
                    GeometryParser geometryParser,
                    Clipping clipping)
 {
     this.cssStyleCascade = cssStyleCascade;
     this.brushParser     = brushParser;
     this.geometryParser  = geometryParser;
     this.clipping        = clipping;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the transformation matrix from top of the cascade
        /// </summary>
        /// <returns></returns>
        public static Matrix GetTransformMatrixFromTop(this CssStyleCascade cssStyleCascade)
        {
            var transform = cssStyleCascade.GetPropertyFromTop("transform");

            if (!string.IsNullOrEmpty(transform))
            {
                return(TransformMatrixParser.GetTransformMatrix(transform));
            }

            return(Matrix.Identity);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get an attribute as double from the level (0 = top)
        /// </summary>
        public static double GetNumberPercentFromLevel(this CssStyleCascade cssStyleCascade, string name, int level, double defaultValue)
        {
            double retVal = defaultValue;

            var strVal = cssStyleCascade.GetPropertyFromLevel(name, level);

            if (!string.IsNullOrEmpty(strVal))
            {
                (_, retVal) = DoubleParser.GetNumberPercent(strVal);
            }

            return(retVal);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get an attribute as double from the cascade
        /// </summary>
        public static double GetNumber(this CssStyleCascade cssStyleCascade, string name, double defaultValue)
        {
            double retVal = defaultValue;

            var strVal = cssStyleCascade.GetProperty(name);

            if (!string.IsNullOrEmpty(strVal))
            {
                retVal = DoubleParser.GetNumber(strVal);
            }

            return(retVal);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Parse an SVG given as XElement root
        /// </summary>
        public GraphicVisual ParseRoot(XElement root)
        {
            var        nameSpaceAttributes       = root.Attributes().Where(a => a.IsNamespaceDeclaration);
            var        defaultNamespaceAttribute = root.Attributes().Where(a => a.IsNamespaceDeclaration && a.Name.Namespace == XNamespace.None).FirstOrDefault();
            XNamespace defaultNamespace          = defaultNamespaceAttribute.Value;

            Matrix currentTransformationMatrix = Matrix.Identity;

            cssStyleCascade = new CssStyleCascade(root);

            ReadGlobalDefinitions(root);
            GraphicVisual visual = ParseGroup(defaultNamespace, root, currentTransformationMatrix);

            visual = OptimizeVisual.Optimize(visual);

            return(visual);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Parse an SVG given as XElement root
        /// </summary>
        public GraphicVisual ParseRoot(XElement root)
        {
            var        nameSpaceAttributes       = root.Attributes().Where(a => a.IsNamespaceDeclaration);
            var        defaultNamespaceAttribute = root.Attributes().Where(a => a.IsNamespaceDeclaration && a.Name.Namespace == XNamespace.None).FirstOrDefault();
            XNamespace defaultNamespace          = defaultNamespaceAttribute.Value;

            Matrix currentTransformationMatrix = Matrix.Identity;

            cssStyleCascade = new CssStyleCascade(root);

            var svgViewBox = new SvgViewBox
            {
                ViewBox = new Rect(0, 0, 100, 100),
                Align   = "none",
                Slice   = "meet"
            };

            cssStyleCascade.PushViewBox(svgViewBox);

            doubleParser = new DoubleParser(cssStyleCascade);
            ReadGlobalDefinitions(root);

            var brushParser    = new BrushParser(defaultNamespace, cssStyleCascade, globalDefinitions, doubleParser);
            var geometryParser = new GeometryParser(doubleParser);

            var geometryTextParser = new GeometryTextParser(cssStyleCascade, doubleParser);

            clipping    = new Clipping(cssStyleCascade, globalDefinitions, geometryParser, geometryTextParser);
            shapeParser = new ShapeParser(cssStyleCascade, brushParser, geometryParser, clipping);
            textParser  = new TextParser(cssStyleCascade, doubleParser, brushParser, clipping);

            GraphicVisual visual = ParseSVG(root, currentTransformationMatrix, true);

            visual = OptimizeVisual.Optimize(visual);

            return(visual);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Get an attribute as double from the top of cascade only
 /// </summary>
 public static double GetNumberPercentFromTop(this CssStyleCascade cssStyleCascade, string name, double defaultValue)
 {
     return(cssStyleCascade.GetNumberPercentFromLevel(name, 0, defaultValue));
 }