FastReport

Форк
0
/
CapSettings.cs 
174 строки · 5.0 Кб
1
using System.ComponentModel;
2
using System.Drawing.Drawing2D;
3
using System.Drawing;
4
using FastReport.Utils;
5

6
namespace FastReport
7
{
8
    /// <summary>
9
    /// Specifies a line cap style.
10
    /// </summary>
11
    public enum CapStyle
12
    {
13
        /// <summary>
14
        /// Specifies a line without a cap.
15
        /// </summary>
16
        None,
17

18
        /// <summary>
19
        /// Specifies a line with a circle cap.
20
        /// </summary>
21
        Circle,
22

23
        /// <summary>
24
        /// Specifies a line with a square cap.
25
        /// </summary>
26
        Square,
27

28
        /// <summary>
29
        /// Specifies a line with a diamond cap.
30
        /// </summary>
31
        Diamond,
32

33

34
        /// <summary>
35
        /// Specifies a line with an arrow cap.
36
        /// </summary>
37
        Arrow
38
    }
39

40
    /// <summary>
41
    /// Specifies a start and end line caps.
42
    /// </summary>
43
    [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
44
    public class CapSettings
45
    {
46
        private float width;
47
        private float height;
48
        private CapStyle style;
49

50
        /// <summary>
51
        /// Gets or sets a width of the cap.
52
        /// </summary>
53
        [DefaultValue(8f)]
54
        public float Width
55
        {
56
            get { return width; }
57
            set { width = value; }
58
        }
59

60
        /// <summary>
61
        /// Gets or sets a height of the cap.
62
        /// </summary>
63
        [DefaultValue(8f)]
64
        public float Height
65
        {
66
            get { return height; }
67
            set { height = value; }
68
        }
69

70
        /// <summary>
71
        /// Gets or sets a cap style.
72
        /// </summary>
73
        [DefaultValue(CapStyle.None)]
74
        public CapStyle Style
75
        {
76
            get { return style; }
77
            set { style = value; }
78
        }
79

80
        internal void GetCustomCapPath(out GraphicsPath path, out float inset)
81
        {
82
            path = new GraphicsPath();
83
            inset = 0;
84
            switch (Style)
85
            {
86
                case CapStyle.Arrow:
87
                    path.AddLine(new PointF(0, 0), new PointF(-Width, -Height));
88
                    path.AddLine(new PointF(0, 0), new PointF(Width, -Height));
89
                    break;
90

91
                case CapStyle.Circle:
92
                    path.AddEllipse(-Width / 2, -Height / 2, Width, Height);
93
                    inset = Height / 2;
94
                    break;
95

96
                case CapStyle.Square:
97
                    path.AddRectangle(new RectangleF(-Width / 2, -Height / 2, Width, Height));
98
                    inset = Height / 2;
99
                    break;
100

101
                case CapStyle.Diamond:
102
                    path.AddLine(new PointF(0, -Height / 1.4f), new PointF(-Width / 1.4f, 0));
103
                    path.AddLine(new PointF(-Width / 1.4f, 0), new PointF(0, Height / 1.4f));
104
                    path.AddLine(new PointF(0, Height / 1.4f), new PointF(Width / 1.4f, 0));
105
                    path.AddLine(new PointF(Width / 1.4f, 0), new PointF(0, -Height / 1.4f));
106
                    inset = Height / 1.4f;
107
                    break;
108
            }
109
        }
110

111
        /// <summary>
112
        /// Assigns values from another source.
113
        /// </summary>
114
        /// <param name="source">Source to assign from.</param>
115
        public void Assign(CapSettings source)
116
        {
117
            Width = source.Width;
118
            Height = source.Height;
119
            Style = source.Style;
120
        }
121

122
        /// <summary>
123
        /// Creates exact copy of this object.
124
        /// </summary>
125
        /// <returns>Copy of this object.</returns>
126
        public CapSettings Clone()
127
        {
128
            CapSettings result = new CapSettings();
129
            result.Assign(this);
130
            return result;
131
        }
132

133
        /// <inheritdoc/>
134
        public override bool Equals(object obj)
135
        {
136
            CapSettings c = obj as CapSettings;
137
            return c != null && Width == c.Width && Height == c.Height && Style == c.Style;
138
        }
139

140
        /// <inheritdoc/>
141
        public override int GetHashCode()
142
        {
143
            return base.GetHashCode();
144
        }
145

146
        /// <summary>
147
        /// Serializes the cap settings.
148
        /// </summary>
149
        /// <param name="prefix">Name of the cap property.</param>
150
        /// <param name="writer">Writer object.</param>
151
        /// <param name="diff">Another cap to compare with.</param>
152
        /// <remarks>
153
        /// This method is for internal use only.
154
        /// </remarks>
155
        public void Serialize(string prefix, FRWriter writer, CapSettings diff)
156
        {
157
            if (Width != diff.Width)
158
                writer.WriteFloat(prefix + ".Width", Width);
159
            if (Height != diff.Height)
160
                writer.WriteFloat(prefix + ".Height", Height);
161
            if (Style != diff.Style)
162
                writer.WriteValue(prefix + ".Style", Style);
163
        }
164

165
        /// <summary>
166
        /// Initializes a new instance of the <b>CapSettings</b> class with default settings. 
167
        /// </summary>
168
        public CapSettings()
169
        {
170
            width = 8;
171
            height = 8;
172
        }
173
    }
174
}
175

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.