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

Fix shadow offsets on dataUrl export #5593

Merged
merged 3 commits into from
Mar 24, 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
3 changes: 3 additions & 0 deletions src/mixins/canvas_dataurl_exporter.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@
originalInteractive = this.interactive,
originalContext = this.contextContainer,
newVp = [newZoom, 0, 0, newZoom, translateX, translateY],
originalRetina = this.enableRetinaScaling,
canvasEl = fabric.util.createCanvasElement();
canvasEl.width = scaledWidth;
canvasEl.height = scaledHeight;
this.enableRetinaScaling = false;
this.interactive = false;
this.viewportTransform = newVp;
this.width = scaledWidth;
Expand All @@ -88,6 +90,7 @@
this.calcViewportBoundaries();
this.contextContainer = originalContext;
this.interactive = originalInteractive;
this.enableRetinaScaling = originalRetina;
return canvasEl;
},
});
Expand Down
Binary file added test/visual/golden/dataurl10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visual/golden/dataurl12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions test/visual/toDataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,133 @@
height: 1800,
});

function toDataURL10(fabricCanvas, callback) {
fabricCanvas.enableRetinaScaling = true;
fabric.devicePixelRatio = 2;
fabricCanvas.setDimensions({
width: 300,
height: 300,
});
var shadow = {
color: 'rgba(0,0,0,0.6)',
blur: 1,
offsetX: 50,
offsetY: 10,
opacity: 0.6,
};

var rect = new fabric.Rect({
left: 10,
top: 10,
fill: '#FF0000',
stroke: '#000',
width: 100,
height: 100,
strokeWidth: 10,
opacity: .8
});

rect.setShadow(shadow);
fabricCanvas.add(rect);
var dataUrl = fabricCanvas.toDataURL({ multiplier: 0.5 });
callback(dataUrl);
}

tests.push({
test: 'shadow offsets dataUrl with retina',
code: toDataURL10,
// use the same golden on purpose
golden: 'dataurl10.png',
percentage: 0.09,
width: 300,
height: 300,
});

function toDataURL11(fabricCanvas, callback) {
fabricCanvas.enableRetinaScaling = false;
fabric.devicePixelRatio = 1;
fabricCanvas.setDimensions({
width: 300,
height: 300,
});
var shadow = {
color: 'rgba(0,0,0,0.6)',
blur: 1,
offsetX: 50,
offsetY: 10,
opacity: 0.6,
};

var rect = new fabric.Rect({
left: 10,
top: 10,
fill: '#FF0000',
stroke: '#000',
width: 100,
height: 100,
strokeWidth: 10,
opacity: .8
});

rect.setShadow(shadow);
fabricCanvas.add(rect);
var dataUrl = fabricCanvas.toDataURL({ multiplier: 0.5 });
callback(dataUrl);
}

tests.push({
test: 'shadow offsets dataUrl without retina',
code: toDataURL11,
// use the same golden on purpose
golden: 'dataurl10.png',
percentage: 0.09,
width: 300,
height: 300,
});

function toDataURL12(fabricCanvas, callback) {
fabricCanvas.enableRetinaScaling = 2;
fabric.devicePixelRatio = 2;
fabricCanvas.setDimensions({
width: 300,
height: 300,
});
var shadow = {
color: 'rgba(0,0,0,0.6)',
blur: 1,
offsetX: 50,
offsetY: 10,
opacity: 0.6,
};

var rect = new fabric.Rect({
left: 10,
top: 10,
fill: '#FF0000',
stroke: '#000',
width: 100,
height: 100,
strokeWidth: 10,
opacity: .8
});

rect.setShadow(shadow);
fabricCanvas.add(rect);
var dataUrl = fabricCanvas.toDataURL({ multiplier: 0.5, enableRetinaScaling: true });
fabric.devicePixelRatio = 1;
callback(dataUrl);
}

tests.push({
test: 'shadow offsets dataUrl with retina and retinaScaling enable in export',
code: toDataURL12,
// use the same golden on purpose
golden: 'dataurl12.png',
percentage: 0.09,
width: 300,
height: 300,
});


function testWrapper(test) {
var actualTest = test.code;
Expand Down