Skip to content

Commit

Permalink
fixes a particular case of clipPath problem (#5477)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Jan 13, 2019
1 parent 1cf38e1 commit 03b98a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,10 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
drawObject: function(ctx, forClipping) {

var originalFill = this.fill, originalStroke = this.stroke;
if (forClipping) {
this.fill = 'black';
this.stroke = '';
this._setClippingProperties(ctx);
}
else {
Expand All @@ -1186,6 +1188,8 @@
}
this._render(ctx);
this._drawClipPath(ctx);
this.fill = originalFill;
this.stroke = originalStroke;
},

_drawClipPath: function(ctx) {
Expand Down
16 changes: 16 additions & 0 deletions test/visual/clippath.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
percentage: 0.06,
});

function clipping02(canvas, callback) {
var clipPath = new fabric.Circle({ radius: 50, strokeWidth: 40, top: -50, left: -50, fill: '' });
var obj = new fabric.Rect({ top: 0, left: 0, strokeWidth: 0, width: 200, height: 200, fill: 'rgba(0,255,0,0.5)'});
obj.clipPath = clipPath;
canvas.add(obj);
canvas.renderAll();
callback(canvas.lowerCanvasEl);
}

tests.push({
test: 'falsy values for fill are handled',
code: clipping02,
golden: 'clipping01.png',
percentage: 0.06,
});

function clipping1(canvas, callback) {
var zoom = 20;
canvas.setZoom(zoom);
Expand Down

0 comments on commit 03b98a0

Please sign in to comment.