mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-08 22:04:44 +00:00
Issue 3832 Add toDatalessObject to Group class since it may contains pathGroups. (#3863)
* fix toDatalessObject * added test
This commit is contained in:
parent
ba19885256
commit
d95612e3c3
3 changed files with 30 additions and 4 deletions
|
|
@ -266,6 +266,24 @@
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns object representation of an instance, in dataless mode.
|
||||
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
||||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toDatalessObject: function(propertiesToInclude) {
|
||||
var objsToObject = this.getObjects().map(function(obj) {
|
||||
var originalDefaults = obj.includeDefaultValues;
|
||||
obj.includeDefaultValues = obj.group.includeDefaultValues;
|
||||
var _obj = obj.toDatalessObject(propertiesToInclude);
|
||||
obj.includeDefaultValues = originalDefaults;
|
||||
return _obj;
|
||||
});
|
||||
return extend(this.callSuper('toDatalessObject', propertiesToInclude), {
|
||||
objects: objsToObject
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders instance on a given context
|
||||
* @param {CanvasRenderingContext2D} ctx context to render instance on
|
||||
|
|
|
|||
|
|
@ -1296,11 +1296,9 @@
|
|||
/**
|
||||
* Renders controls and borders for the object
|
||||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
* @param {Boolean} [noTransform] When true, context is not transformed
|
||||
*/
|
||||
_renderControls: function(ctx, noTransform) {
|
||||
if (!this.active || noTransform
|
||||
|| (this.group && this.group !== this.canvas.getActiveGroup())) {
|
||||
_renderControls: function(ctx) {
|
||||
if (!this.active || (this.group && this.group !== this.canvas.getActiveGroup())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -590,6 +590,16 @@
|
|||
equal(isTransparent(ctx, 11, 11, 0), false, '11,11 is opaque');
|
||||
equal(isTransparent(ctx, 12, 12, 0), true, '12,12 is transparent');
|
||||
});
|
||||
|
||||
test('group toDatalessObject', function() {
|
||||
var rect1 = new fabric.Rect({ top: 1, left: 1, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
|
||||
rect2 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
|
||||
pathGroup = new fabric.PathGroup([rect1, rect2], { sourcePath: 'sourcePath'}),
|
||||
group = new fabric.Group([pathGroup]),
|
||||
dataless = group.toDatalessObject();
|
||||
|
||||
equal(dataless.objects[0].paths, 'sourcePath', 'the paths have been changed with the sourcePath');
|
||||
});
|
||||
// asyncTest('cloning group with image', function() {
|
||||
// var rect = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10 }),
|
||||
// img = new fabric.Image(_createImageElement()),
|
||||
|
|
|
|||
Loading…
Reference in a new issue