diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js index ca98eb0bc7f..e2b36478dc2 100644 --- a/src/shapes/itext.class.js +++ b/src/shapes/itext.class.js @@ -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 }); } }); diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 2569274f79a..7d538f2cf41 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -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) { diff --git a/test/unit/itext.js b/test/unit/itext.js index 9a7faebdbae..237b00749f8 100644 --- a/test/unit/itext.js +++ b/test/unit/itext.js @@ -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() { diff --git a/test/unit/object.js b/test/unit/object.js index 85aee8b9dad..492008d094c 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -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() {