Skip to content

Commit

Permalink
Fixed SvgExport in path with gradient and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claas-c committed Oct 16, 2020
1 parent 4f48cc5 commit 66b6e05
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/gradient.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@
offsetX += object.width / 2;
offsetY += object.height / 2;
}
if (object.type === 'path') {
offsetX -= object.pathOffset.x;
offsetY -= object.pathOffset.y;
}


transform[4] -= offsetX;
transform[5] -= offsetY;
Expand Down
29 changes: 29 additions & 0 deletions test/visual/generic_rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,34 @@
height: 400,
});

function pathWithGradient(canvas, callback) {
var pathWithGradient = new fabric.Path("M 0 0 L 0 100 L 100 100 L 100 0 Z", {
fill: new fabric.Gradient({
gradientUnits: "percentage",
coords: { x1: 0, y1: 0, x2: 0, y2: 1 },
colorStops: [
{ offset: 0, color: "red" },
{ offset: 1, color: "black" }
]
}),
height: 100,
width: 100,
top: 0,
left: 0
});
canvas.add(pathWithGradient);
canvas.renderAll();
callback(canvas.lowerCanvasEl);
}

tests.push({
test: 'gradient should be applied to path',
code: pathWithGradient,
golden: 'pathWithGradient.png',
percentage: 0.06,
width: 100,
height: 100,
});

tests.forEach(visualTestLoop(QUnit));
})();
Binary file added test/visual/golden/pathWithGradient.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/pathWithGradientSvg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions test/visual/z_svg_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,34 @@
width: 760,
height: 760,
});

function pathWithGradientSvg(canvas, callback) {
var pathWithGradient = new fabric.Path("M 0 0 L 0 100 L 100 100 L 100 0 Z", {
fill: new fabric.Gradient({
gradientUnits: "percentage",
coords: { x1: 0, y1: 0, x2: 0, y2: 1 },
colorStops: [
{ offset: 0, color: "red" },
{ offset: 1, color: "black" }
]
}),
height: 100,
width: 100,
top: 0,
left: 0
});
canvas.add(pathWithGradient);
toSVGCanvas(canvas, callback);
}

tests.push({
test: 'gradient should be applied to path in svg',
code: pathWithGradientSvg,
golden: 'pathWithGradientSvg.png',
percentage: 0.06,
width: 100,
height: 100,
});

tests.forEach(visualTestLoop(QUnit));
})();

0 comments on commit 66b6e05

Please sign in to comment.