ShapePolyLine.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.ComponentModel;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Text;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using FastReport.Utils;
  9. namespace FastReport.Map
  10. {
  11. /// <summary>
  12. /// Represents a line shape.
  13. /// </summary>
  14. public class ShapePolyLine : ShapePolygon
  15. {
  16. #region Public Methods
  17. /// <inheritdoc/>
  18. public override void Draw(FRPaintEventArgs e)
  19. {
  20. if (!IsVisible())
  21. return;
  22. float left = Map.AbsLeft + Map.OffsetXG;
  23. float top = Map.AbsTop + Map.OffsetYG;
  24. double minX = Layer.Box.MinX;
  25. double maxY = Layer.Box.MaxY;
  26. double w2 = Box.MinX + (Box.MaxX - Box.MinX) / 2;
  27. double h2 = Box.MinY + (Box.MaxY - Box.MinY) / 2;
  28. double addx = -w2 * ShapeScale + w2 + ShapeOffsetX;
  29. double addy = -h2 * ShapeScale + h2 + ShapeOffsetY;
  30. float scale = Map.ScaleG;
  31. ShapeStyle style = Layer.DefaultShapeStyle;
  32. using (GraphicsPath path = new GraphicsPath())
  33. {
  34. foreach (PointD[] part in Parts)
  35. {
  36. List<PointF> points = new List<PointF>();
  37. foreach (PointD point in part)
  38. {
  39. PointF pt = new PointF(
  40. (left + CoordinateConverter.GetX(point.X * ShapeScale + addx, minX, scale)) * e.ScaleX,
  41. (top + CoordinateConverter.GetY(point.Y * ShapeScale + addy, maxY, scale, Map.MercatorProjection)) * e.ScaleY);
  42. if (points.Count > 0 && DistanceBetweenPoints(pt, points[points.Count - 1]) < Layer.Accuracy)
  43. continue;
  44. points.Add(pt);
  45. }
  46. if (points.Count >= 2)
  47. {
  48. PointF[] poly = points.ToArray();
  49. path.AddLines(poly);
  50. }
  51. }
  52. Pen pen = e.Cache.GetPen(style.BorderColor, style.BorderWidth * e.ScaleX, style.BorderStyle, LineJoin.Bevel);
  53. e.Graphics.DrawPath(pen, path);
  54. }
  55. }
  56. /// <inheritdoc/>
  57. public override void DrawLabel(FRPaintEventArgs e)
  58. {
  59. }
  60. /// <inheritdoc/>
  61. public override bool HitTest(PointF point)
  62. {
  63. if (GetBBox().Contains(point))
  64. return true;
  65. return false;
  66. }
  67. #endregion // Public Methods
  68. /// <summary>
  69. /// Initializes a new instance of the <see cref="ShapePolyLine"/> class.
  70. /// </summary>
  71. public ShapePolyLine()
  72. {
  73. BaseName = "Line";
  74. }
  75. }
  76. }