SvgVisualElementStyle.cs 5.26 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
21
22
23
24
25
26
27
    {
        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>
        [SvgAttribute("visibility")]
        public virtual bool Visible
        {
            get { return (this.Attributes["Visible"] == null) ? true : (bool)this.Attributes["Visible"]; }
            set { this.Attributes["Visible"] = value; }
        }

28
29
30
        /// <summary>
        /// Gets or sets the fill <see cref="SvgPaintServer"/> of this element.
        /// </summary>
davescriven's avatar
davescriven committed
31
32
33
        [SvgAttribute("fill")]
        public virtual SvgPaintServer Fill
        {
34
            get { return (this.Attributes["Fill"] == null) ? new SvgColourServer() : (SvgPaintServer)this.Attributes["Fill"]; }
davescriven's avatar
davescriven committed
35
36
37
            set { this.Attributes["Fill"] = value; }
        }

38
39
40
        /// <summary>
        /// Gets or sets the <see cref="SvgPaintServer"/> to be used when rendering a stroke around this element.
        /// </summary>
davescriven's avatar
davescriven committed
41
42
43
        [SvgAttribute("stroke")]
        public virtual SvgPaintServer Stroke
        {
44
            get { return (this.Attributes["Stroke"] == null) ? null : (SvgPaintServer)this.Attributes["Stroke"]; }
davescriven's avatar
davescriven committed
45
46
47
48
49
50
51
52
53
54
            set { this.Attributes["Stroke"] = value; }
        }

        [SvgAttribute("fill-rule")]
        public virtual SvgFillRule FillRule
        {
            get { return (this.Attributes["FillRule"] == null) ? SvgFillRule.NonZero : (SvgFillRule)this.Attributes["FillRule"]; }
            set { this.Attributes["FillRule"] = value; }
        }

55
56
57
        /// <summary>
        /// Gets or sets the opacity of this element's <see cref="Fill"/>.
        /// </summary>
davescriven's avatar
davescriven committed
58
59
60
61
62
63
64
        [SvgAttribute("fill-opacity")]
        public virtual float FillOpacity
        {
            get { return (this.Attributes["FillOpacity"] == null) ? this.Opacity : (float)this.Attributes["FillOpacity"]; }
            set { this.Attributes["FillOpacity"] = FixOpacityValue(value); }
        }

65
66
67
        /// <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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
        [SvgAttribute("stroke-width")]
        public virtual SvgUnit StrokeWidth
        {
            get { return (this.Attributes["StrokeWidth"] == null) ? new SvgUnit(1.0f) : (SvgUnit)this.Attributes["StrokeWidth"]; }
            set { this.Attributes["StrokeWidth"] = value; }
        }

        [SvgAttribute("stroke-linecap")]
        public virtual SvgStrokeLineCap StrokeLineCap
        {
            get { return (this.Attributes["StrokeLineCap"] == null) ? SvgStrokeLineCap.Butt : (SvgStrokeLineCap)this.Attributes["StrokeLineCap"]; }
            set { this.Attributes["StrokeLineCap"] = value; }
        }

        [SvgAttribute("stroke-linejoin")]
        public virtual SvgStrokeLineJoin StrokeLineJoin
        {
            get { return (this.Attributes["StrokeLineJoin"] == null) ? SvgStrokeLineJoin.Miter : (SvgStrokeLineJoin)this.Attributes["StrokeLineJoin"]; }
            set { this.Attributes["StrokeLineJoin"] = value; }
        }

        [SvgAttribute("stroke-miterlimit")]
        public virtual float StrokeMiterLimit
        {
            get { return (this.Attributes["StrokeMiterLimit"] == null) ? 4.0f : (float)this.Attributes["StrokeMiterLimit"]; }
            set { this.Attributes["StrokeMiterLimit"] = value; }
        }

        [SvgAttribute("stroke-dasharray")]
97
        public virtual SvgUnitCollection StrokeDashArray
davescriven's avatar
davescriven committed
98
        {
99
            get { return this.Attributes["StrokeDashArray"] as SvgUnitCollection; }
davescriven's avatar
davescriven committed
100
101
102
103
104
105
106
107
108
109
            set { this.Attributes["StrokeDashArray"] = value; }
        }

        [SvgAttribute("stroke-dashoffset")]
        public virtual SvgUnit StrokeDashOffset
        {
            get { return (this.Attributes["StrokeDashOffset"] == null) ? SvgUnit.Empty : (SvgUnit)this.Attributes["StrokeDashOffset"]; }
            set { this.Attributes["StrokeDashOffset"] = value; }
        }

110
111
112
        /// <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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
        [SvgAttribute("stroke-opacity")]
        public virtual float StrokeOpacity
        {
            get { return (this.Attributes["StrokeOpacity"] == null) ? this.Opacity : (float)this.Attributes["StrokeOpacity"]; }
            set { this.Attributes["StrokeOpacity"] = FixOpacityValue(value); }
        }

        /// <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
        {
            get { return (this.Attributes["Opacity"] == null) ? 1.0f : (float)this.Attributes["Opacity"]; }
            set { this.Attributes["Opacity"] = FixOpacityValue(value); }
        }
    }
}