Skip to content

Commit

Permalink
fix: bind eraser to initial transform matrix
Browse files Browse the repository at this point in the history
This fixes eraser being positioned against current object transform instead of initial object transform
  • Loading branch information
ShaMan123 committed Apr 7, 2021
1 parent 48634eb commit 302a23b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/brushes/eraser_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
inverted: true,
dirty: true,
eraser: mergedEraserPaths
})
});
obj.freezeClipPathTransformMatrix();
},

/**
Expand Down
10 changes: 9 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,14 @@
return !!this.shadow && (this.shadow.offsetX !== 0 || this.shadow.offsetY !== 0);
},

/**
* Used by @class fabric.EraserBrush to position the erased paths
*/
_clipPathTransformMatrix: null,
freezeClipPathTransformMatrix: function () {
this._clipPathTransformMatrix = this.calcTransformMatrix();
},

/**
* Execute the drawing operation for an object clipPath
* @param {CanvasRenderingContext2D} ctx Context to render on
Expand All @@ -1189,7 +1197,7 @@
}
//ctx.scale(1 / 2, 1 / 2);
if (path.absolutePositioned) {
var m = fabric.util.invertTransform(this.calcTransformMatrix());
var m = fabric.util.invertTransform(this._clipPathTransformMatrix || this.calcTransformMatrix());
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}
path.transform(ctx);
Expand Down

0 comments on commit 302a23b

Please sign in to comment.