using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using FastReport.Utils; namespace FastReport { /// /// Represents a polygon object. /// /// /// Use the Border.Width, Border.Style and Border.Color properties to set /// the line width, style and color. /// /// public partial class PolygonObject : PolyLineObject { #region Protected Methods /// /// Calculate GraphicsPath for draw to page /// /// Pen for lines /// scale by width /// scale by height /// Always returns a non-empty path protected GraphicsPath getPolygonPath(Pen pen, float scaleX, float scaleY) { GraphicsPath gp = base.GetPath(pen, AbsLeft, AbsTop, AbsRight, AbsBottom, scaleX, scaleY); gp.CloseAllFigures(); return gp; } /// /// Draw polyline path to graphics /// /// Event arguments protected override void drawPoly(FRPaintEventArgs e) { float x = (AbsLeft + Border.Width / 2) * e.ScaleX; float y = (AbsTop + Border.Width / 2) * e.ScaleY; float dx = (Width - Border.Width) * e.ScaleX - 1; float dy = (Height - Border.Width) * e.ScaleY - 1; Pen pen; if (polygonSelectionMode == PolygonSelectionMode.MoveAndScale) { pen = e.Cache.GetPen(Border.Color, Border.Width * e.ScaleX, Border.DashStyle); } else pen = e.Cache.GetPen(Border.Color, 1, DashStyle.Solid); Brush brush = null; if (Fill is SolidFill) brush = e.Cache.GetBrush((Fill as SolidFill).Color); else brush = Fill.CreateBrush(new RectangleF(x, y, dx, dy), e.ScaleX, e.ScaleY); DrawUtils.SetPenDashPatternOrStyle(DashPattern, pen, Border); using (GraphicsPath path = getPolygonPath(pen, e.ScaleX, e.ScaleY)) { if (polygonSelectionMode == PolygonSelectionMode.MoveAndScale) e.Graphics.FillAndDrawPath(pen, brush, path); else e.Graphics.DrawPath(pen, path); } } #endregion #region Public Methods /// public override void Serialize(FRWriter writer) { Border.SimpleBorder = true; base.Serialize(writer); PolygonObject c = writer.DiffObject as PolygonObject; } #endregion /// /// Initializes a new instance of the class with default settings. /// public PolygonObject() : base() { FlagSimpleBorder = true; FlagUseFill = true; } } }