Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复箭头放缩变形及比例不一致的问题 #373

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/core/objects/Arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ fabric.Arrow = fabric.util.createClass(fabric.Line, {
_render(ctx) {
this.callSuper('_render', ctx);
ctx.save();
const xDiff = this.x2 - this.x1;
const yDiff = this.y2 - this.y1;
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
const xDiff = (this.x2 - this.x1) * this.scaleX;
const yDiff = (this.y2 - this.y1) * this.scaleY;
const angle = Math.atan2(yDiff, xDiff);
ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
ctx.translate(((this.x2 - this.x1) / 2) * this.scaleX, ((this.y2 - this.y1) / 2) * this.scaleY);
ctx.rotate(angle);
ctx.beginPath();
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
ctx.moveTo(5, 0);
ctx.lineTo(-5, 5);
ctx.lineTo(-5, -5);
ctx.closePath();
ctx.fillStyle = this.stroke;
ctx.lineWidth = this.lineWidth;
ctx.strokeStyle = this.stroke;
ctx.fillStyle = this.fill;
ctx.stroke();
ctx.fill();
ctx.restore();
},
Expand Down
Loading