Geometry.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //MIT, 2015, Michael Popoloski's SharpFont,
  2. //MIT, 2016-present, WinterDev
  3. using System.Numerics;
  4. namespace Typography.OpenFont
  5. {
  6. [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
  7. public struct GlyphPointF
  8. {
  9. //from https://docs.microsoft.com/en-us/typography/opentype/spec/glyf
  10. //'point' of the glyph contour.
  11. //eg. ... In the glyf table, the position of a point ...
  12. // ... the point is on the curve; otherwise, it is off the curve....
  13. internal Vector2 P;
  14. internal bool onCurve;
  15. public GlyphPointF(float x, float y, bool onCurve)
  16. {
  17. P = new Vector2(x, y);
  18. this.onCurve = onCurve;
  19. }
  20. public GlyphPointF(Vector2 position, bool onCurve)
  21. {
  22. P = position;
  23. this.onCurve = onCurve;
  24. }
  25. public float X => this.P.X;
  26. public float Y => this.P.Y;
  27. public static GlyphPointF operator *(GlyphPointF p, float n)
  28. {
  29. return new GlyphPointF(p.P * n, p.onCurve);
  30. }
  31. //-----------------------------------------
  32. internal GlyphPointF Offset(short dx, short dy) { return new GlyphPointF(new Vector2(P.X + dx, P.Y + dy), onCurve); }
  33. internal void ApplyScale(float scale)
  34. {
  35. P *= scale;
  36. }
  37. internal void ApplyScaleOnlyOnXAxis(float scale)
  38. {
  39. P = new Vector2(P.X * scale, P.Y);
  40. }
  41. internal void UpdateX(float x)
  42. {
  43. this.P.X = x;
  44. }
  45. internal void UpdateY(float y)
  46. {
  47. this.P.Y = y;
  48. }
  49. internal void OffsetY(float dy)
  50. {
  51. this.P.Y += dy;
  52. }
  53. internal void OffsetX(float dx)
  54. {
  55. this.P.X += dx;
  56. }
  57. #if DEBUG
  58. internal bool dbugIsEqualsWith(GlyphPointF another)
  59. {
  60. return this.P == another.P && this.onCurve == another.onCurve;
  61. }
  62. public override string ToString() { return P.ToString() + " " + onCurve.ToString(); }
  63. #endif
  64. }
  65. }