Clip path from json (#5279)

* better-than-nothing

* check that the active object exist

* test

* added a test

* added the code

* added a test for this case
This commit is contained in:
Andrea Bogazzi 2018-09-29 13:49:29 -04:00 committed by GitHub
parent fdd2d94e77
commit dd76fa2b6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -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);

View file

@ -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');