FastReport
174 строки · 5.0 Кб
1using System.ComponentModel;
2using System.Drawing.Drawing2D;
3using System.Drawing;
4using FastReport.Utils;
5
6namespace FastReport
7{
8/// <summary>
9/// Specifies a line cap style.
10/// </summary>
11public enum CapStyle
12{
13/// <summary>
14/// Specifies a line without a cap.
15/// </summary>
16None,
17
18/// <summary>
19/// Specifies a line with a circle cap.
20/// </summary>
21Circle,
22
23/// <summary>
24/// Specifies a line with a square cap.
25/// </summary>
26Square,
27
28/// <summary>
29/// Specifies a line with a diamond cap.
30/// </summary>
31Diamond,
32
33
34/// <summary>
35/// Specifies a line with an arrow cap.
36/// </summary>
37Arrow
38}
39
40/// <summary>
41/// Specifies a start and end line caps.
42/// </summary>
43[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
44public class CapSettings
45{
46private float width;
47private float height;
48private CapStyle style;
49
50/// <summary>
51/// Gets or sets a width of the cap.
52/// </summary>
53[DefaultValue(8f)]
54public float Width
55{
56get { return width; }
57set { width = value; }
58}
59
60/// <summary>
61/// Gets or sets a height of the cap.
62/// </summary>
63[DefaultValue(8f)]
64public float Height
65{
66get { return height; }
67set { height = value; }
68}
69
70/// <summary>
71/// Gets or sets a cap style.
72/// </summary>
73[DefaultValue(CapStyle.None)]
74public CapStyle Style
75{
76get { return style; }
77set { style = value; }
78}
79
80internal void GetCustomCapPath(out GraphicsPath path, out float inset)
81{
82path = new GraphicsPath();
83inset = 0;
84switch (Style)
85{
86case CapStyle.Arrow:
87path.AddLine(new PointF(0, 0), new PointF(-Width, -Height));
88path.AddLine(new PointF(0, 0), new PointF(Width, -Height));
89break;
90
91case CapStyle.Circle:
92path.AddEllipse(-Width / 2, -Height / 2, Width, Height);
93inset = Height / 2;
94break;
95
96case CapStyle.Square:
97path.AddRectangle(new RectangleF(-Width / 2, -Height / 2, Width, Height));
98inset = Height / 2;
99break;
100
101case CapStyle.Diamond:
102path.AddLine(new PointF(0, -Height / 1.4f), new PointF(-Width / 1.4f, 0));
103path.AddLine(new PointF(-Width / 1.4f, 0), new PointF(0, Height / 1.4f));
104path.AddLine(new PointF(0, Height / 1.4f), new PointF(Width / 1.4f, 0));
105path.AddLine(new PointF(Width / 1.4f, 0), new PointF(0, -Height / 1.4f));
106inset = Height / 1.4f;
107break;
108}
109}
110
111/// <summary>
112/// Assigns values from another source.
113/// </summary>
114/// <param name="source">Source to assign from.</param>
115public void Assign(CapSettings source)
116{
117Width = source.Width;
118Height = source.Height;
119Style = source.Style;
120}
121
122/// <summary>
123/// Creates exact copy of this object.
124/// </summary>
125/// <returns>Copy of this object.</returns>
126public CapSettings Clone()
127{
128CapSettings result = new CapSettings();
129result.Assign(this);
130return result;
131}
132
133/// <inheritdoc/>
134public override bool Equals(object obj)
135{
136CapSettings c = obj as CapSettings;
137return c != null && Width == c.Width && Height == c.Height && Style == c.Style;
138}
139
140/// <inheritdoc/>
141public override int GetHashCode()
142{
143return 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>
155public void Serialize(string prefix, FRWriter writer, CapSettings diff)
156{
157if (Width != diff.Width)
158writer.WriteFloat(prefix + ".Width", Width);
159if (Height != diff.Height)
160writer.WriteFloat(prefix + ".Height", Height);
161if (Style != diff.Style)
162writer.WriteValue(prefix + ".Style", Style);
163}
164
165/// <summary>
166/// Initializes a new instance of the <b>CapSettings</b> class with default settings.
167/// </summary>
168public CapSettings()
169{
170width = 8;
171height = 8;
172}
173}
174}
175