RadialUtils.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using FastReport.Utils;
  2. using System;
  3. using System.Drawing;
  4. namespace FastReport.Gauge.Radial
  5. {
  6. internal class RadialUtils
  7. {
  8. public static Font GetFont(FRPaintEventArgs e, GaugeObject gauge, Font font)
  9. {
  10. return e.Cache.GetFont(font.FontFamily, gauge.IsPrinting ? font.Size : font.Size * e.ScaleX * 96f / DrawUtils.ScreenDpi, font.Style);
  11. }
  12. public static SizeF GetStringSize(FRPaintEventArgs e, GaugeObject gauge, Font font, string text)
  13. {
  14. return e.Graphics.MeasureString(text, GetFont(e, gauge, font));
  15. }
  16. public static PointF[] RotateVector(PointF[] vector, double angle, PointF center)
  17. {
  18. PointF[] rotatedVector = new PointF[2];
  19. rotatedVector[0].X = (float)(center.X + (vector[0].X - center.X) * Math.Cos(angle) + (center.Y - vector[0].Y) * Math.Sin(angle));
  20. rotatedVector[0].Y = (float)(center.Y + (vector[0].X - center.X) * Math.Sin(angle) + (vector[0].Y - center.Y) * Math.Cos(angle));
  21. rotatedVector[1].X = (float)(center.X + (vector[1].X - center.X) * Math.Cos(angle) + (center.Y - vector[1].Y) * Math.Sin(angle));
  22. rotatedVector[1].Y = (float)(center.Y + (vector[1].X - center.X) * Math.Sin(angle) + (vector[1].Y - center.Y) * Math.Cos(angle));
  23. return rotatedVector;
  24. }
  25. public static bool IsTop(GaugeObject radialGauge)
  26. {
  27. return ((radialGauge as RadialGauge).Position & RadialGaugePosition.Top) != 0;
  28. }
  29. public static bool IsBottom(GaugeObject radialGauge)
  30. {
  31. return ((radialGauge as RadialGauge).Position & RadialGaugePosition.Bottom) != 0;
  32. }
  33. public static bool IsLeft(GaugeObject radialGauge)
  34. {
  35. return ((radialGauge as RadialGauge).Position & RadialGaugePosition.Left) != 0;
  36. }
  37. public static bool IsRight(GaugeObject radialGauge)
  38. {
  39. return ((radialGauge as RadialGauge).Position & RadialGaugePosition.Right) != 0;
  40. }
  41. public static bool IsSemicircle(GaugeObject radialGauge)
  42. {
  43. return ((radialGauge as RadialGauge).Type & RadialGaugeType.Semicircle) != 0;
  44. }
  45. public static bool IsQuadrant(GaugeObject radialGauge)
  46. {
  47. return ((radialGauge as RadialGauge).Type & RadialGaugeType.Quadrant) != 0;
  48. }
  49. }
  50. }