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-5884 fix canvas pattern as background #5973

Merged
merged 2 commits into from
Nov 17, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"testem:ci": "testem ci"
},
"optionalDependencies": {
"canvas": "^2.6.0",
"canvas": "^2.6.1",
"jsdom": "^15.1.0"
},
"devDependencies": {
Expand Down
7 changes: 2 additions & 5 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,12 +1013,9 @@
? fill.toLive(ctx, this)
: fill;
if (needsVpt) {
ctx.transform(
v[0], v[1], v[2], v[3],
v[4] + (fill.offsetX || 0),
v[5] + (fill.offsetY || 0)
);
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
}
ctx.transform(1, 0, 0, 1, fill.offsetX || 0, fill.offsetY || 0);
var m = fill.gradientTransform || fill.patternTransform;
m && ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
ctx.fill();
Expand Down
Binary file added test/fixtures/diet.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions test/visual/generic_rendering.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function() {
var getFixture;
if (fabric.isLikelyNode) {
if (process.env.launcher === 'Firefox') {
fabric.browserShadowBlurConstant = 0.9;
Expand All @@ -12,6 +13,7 @@
if (process.env.launcher === 'Edge') {
fabric.browserShadowBlurConstant = 1.75;
}
getFixture = global.getFixture;
}
else {
if (navigator.userAgent.indexOf('Firefox') !== -1) {
Expand All @@ -23,6 +25,7 @@
if (navigator.userAgent.indexOf('Edge') !== -1) {
fabric.browserShadowBlurConstant = 1.75;
}
getFixture = window.getFixture;
}
fabric.enableGLFiltering = false;
fabric.isWebglSupported = false;
Expand Down Expand Up @@ -260,5 +263,53 @@
height: 300,
});

function canvasPattern(fabricCanvas, callback) {
getFixture('diet.jpeg', false, function(img) {
var pattern = new fabric.Pattern({
source: img,
repeat: 'repeat',
offsetX: -120,
offsetY: 50
});
fabricCanvas.backgroundColor = pattern;
var canvas = fabricCanvas.toCanvasElement();
callback(canvas);
});
}

tests.push({
test: 'canvas with background pattern and export',
code: canvasPattern,
// use the same golden on purpose
golden: 'canvasPattern.png',
percentage: 0.09,
width: 500,
height: 500,
});

function canvasPatternMultiplier(fabricCanvas, callback) {
getFixture('diet.jpeg', false, function(img2) {
var pattern = new fabric.Pattern({
source: img2,
repeat: 'repeat',
offsetX: -120,
offsetY: 50
});
fabricCanvas.backgroundColor = pattern;
var canvas = fabricCanvas.toCanvasElement(0.3);
callback(canvas);
});
}

tests.push({
test: 'canvas with background pattern and multiplier',
code: canvasPatternMultiplier,
// use the same golden on purpose
golden: 'canvasPatternMultiplier.png',
percentage: 0.09,
width: 500,
height: 500,
});

tests.forEach(visualTestLoop(QUnit));
})();
Binary file added test/visual/golden/canvasPattern.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/canvasPatternMultiplier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.