Example #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;
        }
Example #2
0
        /// <summary>
        /// Get a double attribute from a length or percent from the cascade
        /// </summary>
        private double GetLengthPercentFromCascade(string attrName, double defaultValue)
        {
            double retVal;

            var strVal = cssStyleCascade.GetProperty(attrName);

            if (!string.IsNullOrEmpty(strVal))
            {
                retVal = doubleParser.GetLengthPercent(strVal, PercentBaseSelector.ViewBoxDiagonal);
            }
            else
            {
                retVal = defaultValue;
            }

            return(retVal);
        }
Example #3
0
        /// <summary>
        /// Get the font size
        /// </summary>
        private double GetFontSize()
        {
            var    fontSizeStr = cssStyleCascade.GetProperty("font-size");
            double fontSize    = 16.0;

            if (!string.IsNullOrEmpty(fontSizeStr))
            {
                fontSize = GetLengthPercent(fontSizeStr, PercentBaseSelector.ViewBoxDiagonal);
            }

            return(fontSize);
        }