SvgVisualElementStyle.cs 6.2 KB
Newer Older
davescriven's avatar
davescriven committed
1
2
3
4
5
6
7
8
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.ComponentModel;

namespace Svg
{
9
    public abstract partial class SvgVisualElement
davescriven's avatar
davescriven committed
10
11
12
13
14
15
16
17
18
19
20
    {
        private static float FixOpacityValue(float value)
        {
            const float max = 1.0f;
            const float min = 0.0f;
            return Math.Min(Math.Max(value, min), max);
        }

        /// <summary>
        /// Gets or sets a value to determine whether the element will be rendered.
        /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
21
        [TypeConverter(typeof(SvgBoolConverter))]
davescriven's avatar
davescriven committed
22
23
24
        [SvgAttribute("visibility")]
        public virtual bool Visible
        {
C Moore's avatar
C Moore committed
25
            get { return (this.Attributes["visibility"] == null) ? true : (bool)this.Attributes["visibility"]; }
Tebjan Halm's avatar
Tebjan Halm committed
26
            set { this.Attributes["visibility"] = value; }
davescriven's avatar
davescriven committed
27
28
        }

C Moore's avatar
C Moore committed
29
30
31
32
33
34
35
36
37
38
39
        /// <summary>
        /// Gets or sets a value to determine whether the element will be rendered.
        /// Needed to support SVG attribute display="none"
        /// </summary>
        [SvgAttribute("display")]
        public virtual string Display
        {
            get { return this.Attributes["display"] as string; }
            set { this.Attributes["display"] = value; }
        }

C Moore's avatar
C Moore committed
40
41
42
43
44
45
46
47
48
49
50
51
52
        // Displayable - false if attribute display="none", true otherwise
        protected virtual bool Displayable
        {
            get
            {
                string checkForDisplayNone = this.Attributes["display"] as string;
                if ((!string.IsNullOrEmpty(checkForDisplayNone)) && (checkForDisplayNone == "none"))
                    return false;
                else
                    return true;
            }
        }

53
54
55
        /// <summary>
        /// Gets or sets the fill <see cref="SvgPaintServer"/> of this element.
        /// </summary>
davescriven's avatar
davescriven committed
56
57
58
        [SvgAttribute("fill")]
        public virtual SvgPaintServer Fill
        {
59
60
            get { return (this.Attributes["fill"] == null) ? SvgColourServer.NotSet : (SvgPaintServer)this.Attributes["fill"]; }
            set { this.Attributes["fill"] = value; }
davescriven's avatar
davescriven committed
61
62
        }

63
64
65
        /// <summary>
        /// Gets or sets the <see cref="SvgPaintServer"/> to be used when rendering a stroke around this element.
        /// </summary>
davescriven's avatar
davescriven committed
66
67
68
        [SvgAttribute("stroke")]
        public virtual SvgPaintServer Stroke
        {
69
70
            get { return (this.Attributes["stroke"] == null) ? null : (SvgPaintServer)this.Attributes["stroke"]; }
            set { this.Attributes["stroke"] = value; }
davescriven's avatar
davescriven committed
71
72
73
74
75
        }

        [SvgAttribute("fill-rule")]
        public virtual SvgFillRule FillRule
        {
76
77
            get { return (this.Attributes["fill-rule"] == null) ? SvgFillRule.NonZero : (SvgFillRule)this.Attributes["fill-rule"]; }
            set { this.Attributes["fill-rule"] = value; }
davescriven's avatar
davescriven committed
78
79
        }

80
81
82
        /// <summary>
        /// Gets or sets the opacity of this element's <see cref="Fill"/>.
        /// </summary>
davescriven's avatar
davescriven committed
83
84
85
        [SvgAttribute("fill-opacity")]
        public virtual float FillOpacity
        {
86
87
            get { return (this.Attributes["fill-opacity"] == null) ? this.Opacity : (float)this.Attributes["fill-opacity"]; }
            set { this.Attributes["fill-opacity"] = FixOpacityValue(value); }
davescriven's avatar
davescriven committed
88
89
        }

90
91
92
        /// <summary>
        /// Gets or sets the width of the stroke (if the <see cref="Stroke"/> property has a valid value specified.
        /// </summary>
davescriven's avatar
davescriven committed
93
94
95
        [SvgAttribute("stroke-width")]
        public virtual SvgUnit StrokeWidth
        {
96
97
            get { return (this.Attributes["stroke-width"] == null) ? new SvgUnit(1.0f) : (SvgUnit)this.Attributes["stroke-width"]; }
            set { this.Attributes["stroke-width"] = value; }
davescriven's avatar
davescriven committed
98
99
100
101
102
        }

        [SvgAttribute("stroke-linecap")]
        public virtual SvgStrokeLineCap StrokeLineCap
        {
103
104
            get { return (this.Attributes["stroke-linecap"] == null) ? SvgStrokeLineCap.Butt : (SvgStrokeLineCap)this.Attributes["stroke-linecap"]; }
            set { this.Attributes["stroke-linecap"] = value; }
davescriven's avatar
davescriven committed
105
106
107
108
109
        }

        [SvgAttribute("stroke-linejoin")]
        public virtual SvgStrokeLineJoin StrokeLineJoin
        {
110
111
            get { return (this.Attributes["stroke-linejoin"] == null) ? SvgStrokeLineJoin.Miter : (SvgStrokeLineJoin)this.Attributes["stroke-linejoin"]; }
            set { this.Attributes["stroke-linejoin"] = value; }
davescriven's avatar
davescriven committed
112
113
114
115
116
        }

        [SvgAttribute("stroke-miterlimit")]
        public virtual float StrokeMiterLimit
        {
117
118
            get { return (this.Attributes["stroke-miterlimit"] == null) ? 4.0f : (float)this.Attributes["stroke-miterlimit"]; }
            set { this.Attributes["stroke-miterlimit"] = value; }
davescriven's avatar
davescriven committed
119
120
121
        }

        [SvgAttribute("stroke-dasharray")]
122
        public virtual SvgUnitCollection StrokeDashArray
davescriven's avatar
davescriven committed
123
        {
124
125
            get { return this.Attributes["stroke-dasharray"] as SvgUnitCollection; }
            set { this.Attributes["stroke-dasharray"] = value; }
davescriven's avatar
davescriven committed
126
127
128
129
130
        }

        [SvgAttribute("stroke-dashoffset")]
        public virtual SvgUnit StrokeDashOffset
        {
131
132
            get { return (this.Attributes["stroke-dashoffset"] == null) ? SvgUnit.Empty : (SvgUnit)this.Attributes["stroke-dashoffset"]; }
            set { this.Attributes["stroke-dashoffset"] = value; }
davescriven's avatar
davescriven committed
133
134
        }

135
136
137
        /// <summary>
        /// Gets or sets the opacity of the stroke, if the <see cref="Stroke"/> property has been specified. 1.0 is fully opaque; 0.0 is transparent.
        /// </summary>
davescriven's avatar
davescriven committed
138
139
140
        [SvgAttribute("stroke-opacity")]
        public virtual float StrokeOpacity
        {
141
142
            get { return (this.Attributes["stroke-opacity"] == null) ? this.Opacity : (float)this.Attributes["stroke-opacity"]; }
            set { this.Attributes["stroke-opacity"] = FixOpacityValue(value); }
davescriven's avatar
davescriven committed
143
144
145
146
147
148
149
150
        }

        /// <summary>
        /// Gets or sets the opacity of the element. 1.0 is fully opaque; 0.0 is transparent.
        /// </summary>
        [SvgAttribute("opacity")]
        public virtual float Opacity
        {
151
152
            get { return (this.Attributes["opacity"] == null) ? 1.0f : (float)this.Attributes["opacity"]; }
            set { this.Attributes["opacity"] = FixOpacityValue(value); }
davescriven's avatar
davescriven committed
153
154
155
        }
    }
}