File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -21,18 +21,23 @@ fabric.Arrow = fabric.util.createClass(fabric.Line, {
21
21
_render ( ctx ) {
22
22
this . callSuper ( '_render' , ctx ) ;
23
23
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 ;
26
28
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 ) ;
28
30
ctx . rotate ( angle ) ;
29
31
ctx . beginPath ( ) ;
30
32
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
31
33
ctx . moveTo ( 5 , 0 ) ;
32
34
ctx . lineTo ( - 5 , 5 ) ;
33
35
ctx . lineTo ( - 5 , - 5 ) ;
34
36
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 ( ) ;
36
41
ctx . fill ( ) ;
37
42
ctx . restore ( ) ;
38
43
} ,
You can’t perform that action at this time.
0 commit comments