Ejemplo n.º 1
0
        /// <summary>
        /// Set the clipping of the group
        /// </summary>
        public static void SetClipPath(GraphicGroup group,
                                       Matrix currentTransformationMatrix,
                                       CssStyleCascade cssStyleCascade,
                                       Dictionary <string, XElement> globalDefinitions)
        {
            var clipPath = cssStyleCascade.GetPropertyFromTop("clip-path");

            if (string.IsNullOrEmpty(clipPath))
            {
                return;
            }

            if (!clipPath.StartsWith("url(", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            int endUri = clipPath.IndexOf(")", StringComparison.OrdinalIgnoreCase);
            var uri    = clipPath.Substring(4, endUri - 4);

            uri = uri.Trim();
            var id = uri.Substring(1);

            if (!globalDefinitions.ContainsKey(id))
            {
                return;
            }

            var clipElem = globalDefinitions[id];

            // richt now we support only a single path for the clip geometry
            var shapeElement = clipElem.Elements().First();

            if (shapeElement == null)
            {
                return;
            }

            var clipGeometry = GeometryParser.Parse(shapeElement, currentTransformationMatrix);

            clipGeometry.FillRule = GraphicFillRule.NoneZero;

            var clipRule = cssStyleCascade.GetProperty("clip-rule");

            if (!string.IsNullOrEmpty(clipRule))
            {
                switch (clipRule)
                {
                case "evenodd":
                    clipGeometry.FillRule = GraphicFillRule.EvenOdd;
                    break;

                case "nonzero":
                    clipGeometry.FillRule = GraphicFillRule.NoneZero;
                    break;
                }
            }

            group.Clip = clipGeometry;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Clipping(CssStyleCascade cssStyleCascade,
                 Dictionary <string, XElement> globalDefinitions,
                 GeometryParser geometryParser,
                 GeometryTextParser textParser)
 {
     this.cssStyleCascade   = cssStyleCascade;
     this.globalDefinitions = globalDefinitions;
     this.geometryParser    = geometryParser;
     this.textParser        = textParser;
 }