Skip to content

Commit

Permalink
ISSUE-5952 fix toCanvasElement of objects in group (fabricjs#5962)
Browse files Browse the repository at this point in the history
* fix toCanvasElement of objects in group

* added test

* lint
  • Loading branch information
asturur authored and Hristo Chakarov committed Jul 27, 2021
1 parent eb029d5 commit 06e544f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1719,9 +1719,10 @@
options || (options = { });

var utils = fabric.util, origParams = utils.saveObjectTransform(this),
originalGroup = this.group,
originalShadow = this.shadow, abs = Math.abs,
multiplier = (options.multiplier || 1) * (options.enableRetinaScaling ? fabric.devicePixelRatio : 1);

delete this.group;
if (options.withoutTransform) {
utils.resetObjectTransform(this);
}
Expand All @@ -1743,6 +1744,7 @@
else {
scaling = this.getObjectScaling();
}
// consider non scaling shadow.
shadowOffset.x = 2 * Math.round(abs(shadow.offsetX) + shadowBlur) * (abs(scaling.scaleX));
shadowOffset.y = 2 * Math.round(abs(shadow.offsetY) + shadowBlur) * (abs(scaling.scaleY));
}
Expand All @@ -1765,6 +1767,9 @@
var canvasEl = canvas.toCanvasElement(multiplier || 1, options);
this.shadow = originalShadow;
this.canvas = originalCanvas;
if (originalGroup) {
this.group = originalGroup;
}
this.set(origParams).setCoords();
// canvas.dispose will call image.dispose that will nullify the elements
// since this canvas is a simple element for the process, we remove references
Expand Down
18 changes: 18 additions & 0 deletions test/visual/generic_rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,23 @@
height: 300,
});

function objectsInActiveSelections(canvas, callback) {
canvas.setZoom(0.1);
var rect1 = new fabric.Rect({ fill: 'purple', top: 30, left: 50, width: 30, height: 100, angle: 10 });
var rect2 = new fabric.Rect({ fill: 'green', top: 150, left: 10, width: 300, height: 30, angle: -10 });
new fabric.ActiveSelection([rect1, rect2]);
var output = rect1.toCanvasElement();
callback(output);
}

tests.push({
test: 'objects in activeSelection toCanvasElement',
code: objectsInActiveSelections,
golden: 'objectsInActiveSelections.png',
percentage: 0.09,
width: 300,
height: 300,
});

tests.forEach(visualTestLoop(QUnit));
})();
Binary file added test/visual/golden/objectsInActiveSelections.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06e544f

Please sign in to comment.