From 302a23b05a85fa09940b2a11fda3c5056a3020c7 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Wed, 7 Apr 2021 10:10:39 +0300 Subject: [PATCH] fix: bind eraser to initial transform matrix This fixes eraser being positioned against current object transform instead of initial object transform --- src/brushes/eraser_brush.class.js | 3 ++- src/shapes/object.class.js | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/brushes/eraser_brush.class.js b/src/brushes/eraser_brush.class.js index 933eb7d7d0e..fdc9126d59c 100644 --- a/src/brushes/eraser_brush.class.js +++ b/src/brushes/eraser_brush.class.js @@ -140,7 +140,8 @@ inverted: true, dirty: true, eraser: mergedEraserPaths - }) + }); + obj.freezeClipPathTransformMatrix(); }, /** diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index c5d6e4bc026..a0c03231285 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -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 @@ -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);