Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-5952 fix toCanvasElement of objects in group #5962

Merged
merged 3 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,9 +1715,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 @@ -1739,6 +1740,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 @@ -1761,6 +1763,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.