Skip to content

Commit db3ebba

Browse files
fix: 修复箭头放缩变形及比例不一致的问题 (#373)
1 parent f5b9049 commit db3ebba

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/core/objects/Arrow.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ fabric.Arrow = fabric.util.createClass(fabric.Line, {
2121
_render(ctx) {
2222
this.callSuper('_render', ctx);
2323
ctx.save();
24-
const xDiff = this.x2 - this.x1;
25-
const yDiff = this.y2 - this.y1;
24+
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
25+
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
26+
const xDiff = (this.x2 - this.x1) * this.scaleX;
27+
const yDiff = (this.y2 - this.y1) * this.scaleY;
2628
const angle = Math.atan2(yDiff, xDiff);
27-
ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
29+
ctx.translate(((this.x2 - this.x1) / 2) * this.scaleX, ((this.y2 - this.y1) / 2) * this.scaleY);
2830
ctx.rotate(angle);
2931
ctx.beginPath();
3032
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
3133
ctx.moveTo(5, 0);
3234
ctx.lineTo(-5, 5);
3335
ctx.lineTo(-5, -5);
3436
ctx.closePath();
35-
ctx.fillStyle = this.stroke;
37+
ctx.lineWidth = this.lineWidth;
38+
ctx.strokeStyle = this.stroke;
39+
ctx.fillStyle = this.fill;
40+
ctx.stroke();
3641
ctx.fill();
3742
ctx.restore();
3843
},

0 commit comments

Comments
 (0)