Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. public DrawTextSpecialFlipRotate(context: CanvasRenderingContext2D, text: string, coorx: number, coory: number): void
  2. {
  3. context.save();
  4. var flagScaleX = false;
  5. var flagScaleY = false;
  6.  
  7. var rotationThis = this.Context.Rotation;
  8.  
  9. if (this.Context.Rotation >= 360) rotationThis = Geometry.CalculateRotate360(this.Context.Rotation);
  10. else if (this.Context.Rotation <= -360) rotationThis = -Geometry.CalculateRotate360(Math.abs(this.Context.Rotation));
  11.  
  12. var scaleSp: number;
  13. var pointsSp: number;
  14.  
  15. if (this.Context.ScaleX < 0 && this.Context.ScaleY < 0)
  16. {
  17. scaleSp = Math.abs(this.Context.ScaleX);
  18. pointsSp = Math.round(11 / scaleSp * 10) / 10;
  19. context.font = pointsSp + "pt Segoe UI, Arial, Tahoma, Verdana, sans-serif";
  20. context.scale(-1, -1);
  21. flagScaleX = true;
  22. flagScaleY = true;
  23. }
  24. else
  25. {
  26. if (this.Context.ScaleX < 0)
  27. { // Flip horizontal
  28.  
  29. scaleSp = Math.abs(this.Context.ScaleX);
  30. pointsSp = Math.round(11 / scaleSp * 10) / 10;
  31. context.font = pointsSp + "pt Segoe UI, Arial, Tahoma, Verdana, sans-serif";
  32. context.scale(-1, 1);
  33. flagScaleX = true;
  34.  
  35. }
  36. else if (this.Context.ScaleY < 0)
  37. { // Flip vertical
  38.  
  39. scaleSp = Math.abs(this.Context.ScaleX);
  40. pointsSp = Math.round(11 / scaleSp * 10) / 10;
  41. context.font = pointsSp + "pt Segoe UI, Arial, Tahoma, Verdana, sans-serif";
  42. context.scale(1, -1);
  43. flagScaleY = true;
  44. }
  45. }
  46.  
  47. // BUG: Both actions are the same
  48. if (this.Context.Rotation <= 0)
  49. context.rotate(-(this.Context.Rotation / (180.0 / Math.PI)));
  50. else
  51. context.rotate(-(this.Context.Rotation / (180.0 / Math.PI)));
  52.  
  53. var xN1;
  54. var yN1;
  55. var radians;
  56.  
  57. if (rotationThis === 0)
  58. {
  59. xN1 = coorx;
  60. yN1 = coory;
  61. }
  62. else
  63. {
  64. radians = -(rotationThis / 180.0 * Math.PI);
  65. xN1 = coorx * Math.cos(-radians) - coory * Math.sin(-radians);
  66. yN1 = coorx * Math.sin(-radians) + coory * Math.cos(-radians);
  67. }
  68.  
  69. if (flagScaleX)
  70. {
  71. radians = -(rotationThis / 180.0 * Math.PI);
  72. xN1 = coorx * Math.cos(radians) - coory * Math.sin(radians);
  73. yN1 = (coorx * Math.sin(radians) + coory * Math.cos(radians));
  74. xN1 = -xN1;
  75. }
  76. else if (flagScaleY)
  77. {
  78. radians = -(rotationThis / 180.0 * Math.PI);
  79. xN1 = coorx * Math.cos(radians) - coory * Math.sin(radians);
  80. yN1 = (coorx * Math.sin(radians) + coory * Math.cos(radians));
  81. yN1 = -yN1;
  82. }
  83.  
  84. if (flagScaleX && flagScaleY)
  85. {
  86. radians = -(rotationThis / 180.0 * Math.PI);
  87. xN1 = coorx * Math.cos(-radians) - coory * Math.sin(-radians);
  88. yN1 = (coorx * Math.sin(-radians) + coory * Math.cos(-radians));
  89. xN1 = -xN1;
  90. yN1 = -yN1;
  91. }
  92.  
  93. context.fillStyle = context.strokeStyle;
  94. context.fillText(text, xN1, yN1);
  95. context.restore();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement