private static IEnumerable <PathWithStyle> ExtractPaths(ElementWithChildren element, StringDictionary parentStyle)
        {
            var style = StyleHelper.MergeStyles(parentStyle, Styler.GetStyle(element));

            foreach (var child in element.Children)
            {
                if (child is Path path)
                {
                    yield return(new PathWithStyle(path, StyleHelper.MergeStyles(style, path.Style)));
                }
                if (child is ElementWithChildren)
                {
                    foreach (var x in ExtractPaths((ElementWithChildren)child, style))
                    {
                        yield return(x);
                    }
                }
            }
        }
        private void Init(Group group, SvgPath svgPath, StringDictionary parentStyle)
        {
            var style = StyleHelper.MergeStyles(parentStyle, svgPath.Style);

            Init(group, svgPath.Transform, style);
            var vdPath = group.Children.Append <VdPath>();

            vdPath.PathData = PathDataFixer.Fix(svgPath.D);

            foreach (string key in style.Keys)
            {
                var value = style[key];
                switch (key)
                {
                case "fill":
                    if (value.StartsWith("#"))
                    {
                        vdPath.FillColor = value;
                    }
                    break;

                case "stroke":
                    if (value.StartsWith("#"))
                    {
                        vdPath.StrokeColor = value;
                    }
                    break;

                case "stroke-width":
                    vdPath.StrokeWidth = float.Parse(value, CultureInfo.InvariantCulture);
                    break;

                case "stroke-opacity":
                    vdPath.StrokeAlpha = float.Parse(value, CultureInfo.InvariantCulture);
                    break;

                case "fill-opacity":
                    vdPath.FillAlpha = float.Parse(value, CultureInfo.InvariantCulture);
                    break;

                case "stroke-linecap":
                    vdPath.StrokeLineCap = value;
                    break;

                case "stroke-linejoin":
                    vdPath.StrokeLineJoin = value;
                    break;

                case "stroke-miterlimit":
                    vdPath.StrokeMiterLimit = value;
                    break;

                case "fill-rule":
                    SetFillType(vdPath, value);
                    break;

                case "stroke-dasharray":
                    _isStrokeDasharrayUsed |= value != "none";
                    break;
                }
            }
        }
Exemple #3
0
        private void Init(Group outerGroup, Group innerGroup, SvgPath svgPath, StringDictionary parentStyle)
        {
            var style = StyleHelper.MergeStyles(parentStyle, svgPath.Style);

            Init(outerGroup, innerGroup, svgPath.Transform, style);
            var fillPath   = innerGroup.Children.Append <VdPath>();
            var strokePath = fillPath;

            fillPath.PathData = svgPath.D;
            if (style.ContainsKey("fill") && SetFillType(fillPath, style["fill-rule"]))
            {
                strokePath          = innerGroup.Children.Append <VdPath>();
                strokePath.PathData = PathDataFixer.Fix(svgPath.D);
            }
            fillPath.PathData = PathDataFixer.Fix(fillPath.PathData);

            foreach (string key in style.Keys)
            {
                var value = style[key];
                switch (key)
                {
                case "fill":
                    if (value.StartsWith("#"))
                    {
                        fillPath.FillColor = value;
                    }
                    break;

                case "stroke":
                    if (value.StartsWith("#"))
                    {
                        strokePath.StrokeColor = value;
                    }
                    break;

                case "stroke-width":
                    strokePath.StrokeWidth = (float)UnitConverter.ConvertToPx(value, 0);
                    break;

                case "stroke-opacity":
                    strokePath.StrokeAlpha *= float.Parse(value, CultureInfo.InvariantCulture);
                    break;

                case "fill-opacity":
                    fillPath.FillAlpha *= float.Parse(value, CultureInfo.InvariantCulture);
                    break;

                case "opacity":
                    strokePath.StrokeAlpha *= float.Parse(value, CultureInfo.InvariantCulture);
                    fillPath.FillAlpha     *= float.Parse(value, CultureInfo.InvariantCulture);
                    break;

                case "stroke-linecap":
                    strokePath.StrokeLineCap = value;
                    break;

                case "stroke-linejoin":
                    strokePath.StrokeLineJoin = value;
                    break;

                case "stroke-miterlimit":
                    strokePath.StrokeMiterLimit = value;
                    break;

                case "stroke-dasharray":
                    _isStrokeDasharrayUsed |= value != "none";
                    break;
                }
            }
        }