mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-04 03:44:45 +00:00
added test (#5344)
This commit is contained in:
parent
40de484881
commit
0a76ff3111
2 changed files with 38 additions and 3 deletions
|
|
@ -558,9 +558,12 @@
|
|||
*/
|
||||
fabric.Group.fromObject = function(object, callback) {
|
||||
fabric.util.enlivenObjects(object.objects, function(enlivenedObjects) {
|
||||
var options = fabric.util.object.clone(object, true);
|
||||
delete options.objects;
|
||||
callback && callback(new fabric.Group(enlivenedObjects, options, true));
|
||||
fabric.util.enlivenObjects([object.clipPath], function(enlivedClipPath) {
|
||||
var options = fabric.util.object.clone(object, true);
|
||||
options.clipPath = enlivedClipPath[0];
|
||||
delete options.objects;
|
||||
callback && callback(new fabric.Group(enlivenedObjects, options, true));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -385,6 +385,38 @@
|
|||
});
|
||||
});
|
||||
|
||||
QUnit.test('fromObject with clipPath', function(assert) {
|
||||
var done = assert.async();
|
||||
var clipPath = new fabric.Rect({
|
||||
width: 500,
|
||||
height: 250,
|
||||
top: 0,
|
||||
left: 0,
|
||||
absolutePositioned: true
|
||||
});
|
||||
|
||||
var groupObject = new fabric.Group([
|
||||
new fabric.Rect({ width: 100, height: 100, fill: 'red' }),
|
||||
new fabric.Rect({ width: 100, height: 100, fill: 'yellow', left: 100 }),
|
||||
new fabric.Rect({ width: 100, height: 100, fill: 'blue', top: 100 }),
|
||||
new fabric.Rect({ width: 100, height: 100, fill: 'green', left: 100, top: 100 })
|
||||
]);
|
||||
groupObject.clipPath = clipPath;
|
||||
|
||||
var groupToObject = groupObject.toObject();
|
||||
|
||||
fabric.Group.fromObject(groupToObject, function(newGroupFromObject) {
|
||||
|
||||
var objectFromNewGroup = newGroupFromObject.toObject();
|
||||
|
||||
assert.ok(newGroupFromObject instanceof fabric.Group);
|
||||
assert.ok(newGroupFromObject.clipPath instanceof fabric.Rect, 'clipPath has been restored');
|
||||
assert.deepEqual(objectFromNewGroup, groupToObject, 'double serialization gives same results');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('fromObject restores oCoords', function(assert) {
|
||||
var done = assert.async();
|
||||
var group = makeGroupWith2ObjectsWithOpacity();
|
||||
|
|
|
|||
Loading…
Reference in a new issue