Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DrawTextSpecialFlipRotate(context: CanvasRenderingContext2D, text: string, coorx: number, coory: number): void
- {
- context.save();
- var flagScaleX = false;
- var flagScaleY = false;
- var rotationThis = this.Context.Rotation;
- if (this.Context.Rotation >= 360) rotationThis = Geometry.CalculateRotate360(this.Context.Rotation);
- else if (this.Context.Rotation <= -360) rotationThis = -Geometry.CalculateRotate360(Math.abs(this.Context.Rotation));
- var scaleSp: number;
- var pointsSp: number;
- if (this.Context.ScaleX < 0 && this.Context.ScaleY < 0)
- {
- scaleSp = Math.abs(this.Context.ScaleX);
- pointsSp = Math.round(11 / scaleSp * 10) / 10;
- context.font = pointsSp + "pt Segoe UI, Arial, Tahoma, Verdana, sans-serif";
- context.scale(-1, -1);
- flagScaleX = true;
- flagScaleY = true;
- }
- else
- {
- if (this.Context.ScaleX < 0)
- { // Flip horizontal
- scaleSp = Math.abs(this.Context.ScaleX);
- pointsSp = Math.round(11 / scaleSp * 10) / 10;
- context.font = pointsSp + "pt Segoe UI, Arial, Tahoma, Verdana, sans-serif";
- context.scale(-1, 1);
- flagScaleX = true;
- }
- else if (this.Context.ScaleY < 0)
- { // Flip vertical
- scaleSp = Math.abs(this.Context.ScaleX);
- pointsSp = Math.round(11 / scaleSp * 10) / 10;
- context.font = pointsSp + "pt Segoe UI, Arial, Tahoma, Verdana, sans-serif";
- context.scale(1, -1);
- flagScaleY = true;
- }
- }
- // BUG: Both actions are the same
- if (this.Context.Rotation <= 0)
- context.rotate(-(this.Context.Rotation / (180.0 / Math.PI)));
- else
- context.rotate(-(this.Context.Rotation / (180.0 / Math.PI)));
- var xN1;
- var yN1;
- var radians;
- if (rotationThis === 0)
- {
- xN1 = coorx;
- yN1 = coory;
- }
- else
- {
- radians = -(rotationThis / 180.0 * Math.PI);
- xN1 = coorx * Math.cos(-radians) - coory * Math.sin(-radians);
- yN1 = coorx * Math.sin(-radians) + coory * Math.cos(-radians);
- }
- if (flagScaleX)
- {
- radians = -(rotationThis / 180.0 * Math.PI);
- xN1 = coorx * Math.cos(radians) - coory * Math.sin(radians);
- yN1 = (coorx * Math.sin(radians) + coory * Math.cos(radians));
- xN1 = -xN1;
- }
- else if (flagScaleY)
- {
- radians = -(rotationThis / 180.0 * Math.PI);
- xN1 = coorx * Math.cos(radians) - coory * Math.sin(radians);
- yN1 = (coorx * Math.sin(radians) + coory * Math.cos(radians));
- yN1 = -yN1;
- }
- if (flagScaleX && flagScaleY)
- {
- radians = -(rotationThis / 180.0 * Math.PI);
- xN1 = coorx * Math.cos(-radians) - coory * Math.sin(-radians);
- yN1 = (coorx * Math.sin(-radians) + coory * Math.cos(-radians));
- xN1 = -xN1;
- yN1 = -yN1;
- }
- context.fillStyle = context.strokeStyle;
- context.fillText(text, xN1, yN1);
- context.restore();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement