using System.ComponentModel; using System.Drawing.Drawing2D; using System.Drawing; using FastReport.Utils; namespace FastReport { /// /// Specifies a line cap style. /// public enum CapStyle { /// /// Specifies a line without a cap. /// None, /// /// Specifies a line with a circle cap. /// Circle, /// /// Specifies a line with a square cap. /// Square, /// /// Specifies a line with a diamond cap. /// Diamond, /// /// Specifies a line with an arrow cap. /// Arrow } /// /// Specifies a start and end line caps. /// [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))] public class CapSettings { private float width; private float height; private CapStyle style; /// /// Gets or sets a width of the cap. /// [DefaultValue(8f)] public float Width { get { return width; } set { width = value; } } /// /// Gets or sets a height of the cap. /// [DefaultValue(8f)] public float Height { get { return height; } set { height = value; } } /// /// Gets or sets a cap style. /// [DefaultValue(CapStyle.None)] public CapStyle Style { get { return style; } set { style = value; } } internal void GetCustomCapPath(out GraphicsPath path, out float inset) { path = new GraphicsPath(); inset = 0; switch (Style) { case CapStyle.Arrow: path.AddLine(new PointF(0, 0), new PointF(-Width, -Height)); path.AddLine(new PointF(0, 0), new PointF(Width, -Height)); break; case CapStyle.Circle: path.AddEllipse(-Width / 2, -Height / 2, Width, Height); inset = Height / 2; break; case CapStyle.Square: path.AddRectangle(new RectangleF(-Width / 2, -Height / 2, Width, Height)); inset = Height / 2; break; case CapStyle.Diamond: path.AddLine(new PointF(0, -Height / 1.4f), new PointF(-Width / 1.4f, 0)); path.AddLine(new PointF(-Width / 1.4f, 0), new PointF(0, Height / 1.4f)); path.AddLine(new PointF(0, Height / 1.4f), new PointF(Width / 1.4f, 0)); path.AddLine(new PointF(Width / 1.4f, 0), new PointF(0, -Height / 1.4f)); inset = Height / 1.4f; break; } } /// /// Assigns values from another source. /// /// Source to assign from. public void Assign(CapSettings source) { Width = source.Width; Height = source.Height; Style = source.Style; } /// /// Creates exact copy of this object. /// /// Copy of this object. public CapSettings Clone() { CapSettings result = new CapSettings(); result.Assign(this); return result; } /// public override bool Equals(object obj) { CapSettings c = obj as CapSettings; return c != null && Width == c.Width && Height == c.Height && Style == c.Style; } /// public override int GetHashCode() { return base.GetHashCode(); } /// /// Serializes the cap settings. /// /// Name of the cap property. /// Writer object. /// Another cap to compare with. /// /// This method is for internal use only. /// public void Serialize(string prefix, FRWriter writer, CapSettings diff) { if (Width != diff.Width) writer.WriteFloat(prefix + ".Width", Width); if (Height != diff.Height) writer.WriteFloat(prefix + ".Height", Height); if (Style != diff.Style) writer.WriteValue(prefix + ".Style", Style); } /// /// Initializes a new instance of the CapSettings class with default settings. /// public CapSettings() { width = 8; height = 8; } } }