SvgDefinitionDefaults.cs 3.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Svg
{
    /// <summary>
    /// Holds a dictionary of the default values of the SVG specification 
    /// </summary>
    public static class SvgDefaults
    {
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        // defaults that are specific to some elements
        private static Dictionary<string, Dictionary<string, string>> _propDefaults = 
            new Dictionary<string, Dictionary<string, string>>
            {
                { "SvgRadialGradientServer", new Dictionary<string, string>
                { { "cx", "50%" }, { "cy", "50%" }, { "r", "50%" } } },
                { "SvgLinearGradientServer", new Dictionary<string, string>
                { { "x1", "0%" }, { "x2", "100%" }, { "y1", "0%" }, { "y2", "100%" }  } },
            };

        // common defaults
        private static readonly Dictionary<string, string> _defaults =
            new Dictionary<string, string>()
            {
                { "d", "" },
                { "viewBox", "0, 0, 0, 0" },
                { "visibility", "visible" },
                { "display", "inline" },
                { "enable-background", "accumulate" },
                { "opacity", "1" },
                { "clip", "auto" },
                { "clip-rule", "nonzero" },
                { "clipPathUnits", "userSpaceOnUse" },
                { "transform", "" },

                // line
                { "x1", "0" },
                { "x2", "0" },
                { "y1", "0" },
                { "y2", "0" },

                // circle, ellipse
                { "cx", "0" },
                { "cy", "0" },

                { "fill", "" },
                { "fill-opacity", "1" },
                { "fill-rule", "nonzero" },

                { "stop-color", "black" },
                { "stop-opacity", "1" },

                { "stroke", "none" },
                { "stroke-opacity", "1" },
                { "stroke-width", "1" },
                { "stroke-miterlimit", "4" },
                { "stroke-linecap", "butt" },
                { "stroke-linejoin", "miter" },
                { "stroke-dasharray", "none" },
                { "stroke-dashoffset", "0" },

                // marker
                { "markerUnits", "strokeWidth" },
                { "refX", "0" },
                { "refY", "0" },
                { "markerWidth", "3" },
                { "markerHeight", "3" },
                { "orient", "0" }
            };

73
74
75
76
77
78
79
80
81

        static SvgDefaults()
        {
        }

        /// <summary>
        /// Checks whether the property value is the default value of the svg definition.
        /// </summary>
        /// <param name="attributeName">Name of the svg attribute</param>
82
        /// <param name="componentType">Class name of the svg element</param>
83
        /// <param name="value">.NET value of the attribute</param>
84
        public static bool IsDefault(string attributeName, string componentType, string value)
85
        {
86
87
88
89
90
91
92
93
            if (_propDefaults.ContainsKey(componentType))
            {
                if (_propDefaults[componentType].ContainsKey(attributeName))
                {
                    return _propDefaults[componentType][attributeName] == value;
                }
            }

94
95
            if (_defaults.ContainsKey(attributeName))
            {
96
                return _defaults[attributeName] == value;
97
98
99
100
101
            }
            return false;
        }
    }
}