Skip to content

Commit

Permalink
Clip path from json (fabricjs#5279)
Browse files Browse the repository at this point in the history
* better-than-nothing

* check that the active object exist

* test

* added a test

* added the code

* added a test for this case
  • Loading branch information
asturur authored Sep 29, 2018
1 parent b71aa21 commit c7a0c5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,11 @@
object.filters = filters || [];
fabric.Image.prototype._initFilters.call(object, [object.resizeFilter], function(resizeFilters) {
object.resizeFilter = resizeFilters[0];
var image = new fabric.Image(img, object);
callback(image);
fabric.util.enlivenObjects([object.clipPath], function(enlivedProps) {
object.clipPath = enlivedProps[0];
var image = new fabric.Image(img, object);
callback(image);
});
});
});
}, null, object.crossOrigin);
Expand Down
14 changes: 14 additions & 0 deletions test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@
});
});

QUnit.test('fromObject with clipPath', function(assert) {
var done = assert.async();
// should not throw error when no callback is given
var obj = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_IMG_OBJECT), {
src: IMG_SRC,
clipPath: (new fabric.Rect({ width: 100, height: 100 })).toObject(),
});
fabric.Image.fromObject(obj, function(instance){
assert.ok(instance instanceof fabric.Image);
assert.ok(instance.clipPath instanceof fabric.Rect);
done();
});
});

QUnit.test('fromObject does not mutate data', function(assert) {
var done = assert.async();
assert.ok(typeof fabric.Image.fromObject === 'function');
Expand Down

0 comments on commit c7a0c5b

Please sign in to comment.