mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-09 22:34:43 +00:00
Merge pull request #2407 from asturur/deep-clo
Deep clone transformMatrix, strokeDashArray and styles properties
This commit is contained in:
commit
db343783d4
4 changed files with 28 additions and 8 deletions
|
|
@ -1121,8 +1121,16 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function(propertiesToInclude) {
|
||||
var clonedStyles = { }, i, j, row;
|
||||
for (i in this.styles) {
|
||||
row = this.styles[i];
|
||||
clonedStyles[i] = { };
|
||||
for (j in row) {
|
||||
clonedStyles[i][j] = clone(row[j]);
|
||||
}
|
||||
}
|
||||
return fabric.util.object.extend(this.callSuper('toObject', propertiesToInclude), {
|
||||
styles: clone(this.styles)
|
||||
styles: clonedStyles
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -783,7 +783,7 @@
|
|||
fill: (this.fill && this.fill.toObject) ? this.fill.toObject() : this.fill,
|
||||
stroke: (this.stroke && this.stroke.toObject) ? this.stroke.toObject() : this.stroke,
|
||||
strokeWidth: toFixed(this.strokeWidth, NUM_FRACTION_DIGITS),
|
||||
strokeDashArray: this.strokeDashArray,
|
||||
strokeDashArray: this.strokeDashArray ? this.strokeDashArray.concat() : this.strokeDashArray,
|
||||
strokeLineCap: this.strokeLineCap,
|
||||
strokeLineJoin: this.strokeLineJoin,
|
||||
strokeMiterLimit: toFixed(this.strokeMiterLimit, NUM_FRACTION_DIGITS),
|
||||
|
|
@ -799,7 +799,7 @@
|
|||
backgroundColor: this.backgroundColor,
|
||||
fillRule: this.fillRule,
|
||||
globalCompositeOperation: this.globalCompositeOperation,
|
||||
transformMatrix: this.transformMatrix
|
||||
transformMatrix: this.transformMatrix ? this.transformMatrix.concat() : this.transformMatrix
|
||||
};
|
||||
|
||||
if (!this.includeDefaultValues) {
|
||||
|
|
|
|||
|
|
@ -110,6 +110,10 @@
|
|||
|
||||
var obj = iText.toObject();
|
||||
deepEqual(obj.styles, styles);
|
||||
notEqual(obj.styles[0], styles[0]);
|
||||
notEqual(obj.styles[0][1], styles[0][1]);
|
||||
deepEqual(obj.styles[0], styles[0]);
|
||||
deepEqual(obj.styles[0][1], styles[0][1]);
|
||||
});
|
||||
|
||||
test('setSelectionStart', function() {
|
||||
|
|
|
|||
|
|
@ -292,10 +292,12 @@
|
|||
strokeLineJoin: 'bevil',
|
||||
strokeMiterLimit: 5,
|
||||
flipX: true,
|
||||
opacity: 0.13
|
||||
opacity: 0.13,
|
||||
transformMatrix: [3, 0, 3, 1, 0, 0]
|
||||
};
|
||||
|
||||
var cObj = new fabric.Object();
|
||||
var cObj = new fabric.Object(),
|
||||
toObjectObj;
|
||||
cObj.includeDefaultValues = false;
|
||||
deepEqual(emptyObjectRepr, cObj.toObject());
|
||||
|
||||
|
|
@ -308,9 +310,15 @@
|
|||
.set('strokeDashArray', [5, 2])
|
||||
.set('strokeLineCap', 'round')
|
||||
.set('strokeLineJoin', 'bevil')
|
||||
.set('strokeMiterLimit', 5);
|
||||
|
||||
deepEqual(augmentedObjectRepr, cObj.toObject());
|
||||
.set('strokeMiterLimit', 5)
|
||||
.set('transformMatrix', [3, 0, 3, 1, 0, 0]);
|
||||
toObjectObj = cObj.toObject();
|
||||
deepEqual(augmentedObjectRepr, toObjectObj);
|
||||
notEqual(augmentedObjectRepr.transformMatrix, toObjectObj.transformMatrix);
|
||||
deepEqual(augmentedObjectRepr.transformMatrix, toObjectObj.transformMatrix);
|
||||
notEqual(augmentedObjectRepr.strokeDashArray, toObjectObj.strokeDashArray);
|
||||
deepEqual(augmentedObjectRepr.strokeDashArray, toObjectObj.strokeDashArray);
|
||||
|
||||
});
|
||||
|
||||
test('toDatalessObject', function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue