Skip to content

Commit

Permalink
Fix for when toObjects is called on a canvas with a clipPath (#5556)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthify authored and asturur committed Mar 15, 2019
1 parent abc1ca2 commit 3ac5207
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/static_canvas.class.js
Original file line number Diff line number Diff line change
@@ -1177,7 +1177,7 @@
objects: this._toObjects(methodName, propertiesToInclude),
};
if (clipPath) {
data.clipPath = this._toObjectMethod(clipPath, methodName, propertiesToInclude);
data.clipPath = this._toObject(this.clipPath, methodName, propertiesToInclude);
}
extend(data, this.__serializeBgOverlay(methodName, propertiesToInclude));

55 changes: 55 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
@@ -1290,12 +1290,67 @@
assert.equal(canvas.toObject().objects[0].type, rect.type);
});


QUnit.test('toObject with clipPath', function(assert) {
var clipPath = makeRect();
var canvasWithClipPath = new fabric.Canvas(null, { clipPath: clipPath });
var expectedObject = {
'version': fabric.version,
objects: canvasWithClipPath.getObjects(),
clipPath: {
type: 'rect',
version: fabric.version,
originX: 'left',
originY: 'top',
left: 0,
top: 0,
width: 10,
height: 10,
fill: 'rgb(0,0,0)',
stroke: null,
strokeWidth: 1,
strokeDashArray: null,
strokeLineCap: 'butt',
strokeDashOffset: 0,
strokeLineJoin: 'miter',
strokeMiterLimit: 4,
scaleX: 1,
scaleY: 1,
angle: 0,
flipX: false,
flipY: false,
opacity: 1,
shadow: null,
visible: true,
clipTo: null,
backgroundColor: '',
fillRule: 'nonzero',
paintFirst: 'fill',
globalCompositeOperation: 'source-over',
transformMatrix: null,
skewX: 0,
skewY: 0,
rx: 0,
ry: 0
}
};

assert.ok(typeof canvasWithClipPath.toObject === 'function');
assert.deepEqual(expectedObject, canvasWithClipPath.toObject());

var rect = makeRect();
canvasWithClipPath.add(rect);

assert.equal(canvasWithClipPath.toObject().objects[0].type, rect.type);
});

QUnit.test('toDatalessObject', function(assert) {
assert.ok(typeof canvas.toDatalessObject === 'function');
var expectedObject = {
'version': fabric.version,
objects: canvas.getObjects()
};

assert.deepEqual(expectedObject, canvas.toDatalessObject());

var rect = makeRect();

0 comments on commit 3ac5207

Please sign in to comment.