Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To object origin #3416

Merged
merged 5 commits into from
Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/shapes/circle.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
return extend(this.callSuper('toObject', propertiesToInclude), {
radius: this.get('radius'),
startAngle: this.startAngle,
endAngle: this.endAngle
});
return this.callSuper('toObject', ['radius', 'startAngle', 'endAngle'].concat(propertiesToInclude));
},

/* _TO_SVG_START_ */
Expand Down
5 changes: 1 addition & 4 deletions src/shapes/ellipse.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
return extend(this.callSuper('toObject', propertiesToInclude), {
rx: this.get('rx'),
ry: this.get('ry')
});
return this.callSuper('toObject', ['rx', 'ry'].concat(propertiesToInclude));
},

/* _TO_SVG_START_ */
Expand Down
23 changes: 9 additions & 14 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,19 @@
this.resizeFilters.forEach(function(filterObj) {
filterObj && resizeFilters.push(filterObj.toObject());
});

var object = extend(this.callSuper('toObject', propertiesToInclude), {
src: this.getSrc(),
filters: filters,
resizeFilters: resizeFilters,
crossOrigin: this.crossOrigin,
alignX: this.alignX,
alignY: this.alignY,
meetOrSlice: this.meetOrSlice
});
var object = extend(
this.callSuper(
'toObject',
['crossOrigin', 'alignX', 'alignY', 'meetOrSlice'].concat(propertiesToInclude)
), {
src: this.getSrc(),
filters: filters,
resizeFilters: resizeFilters,
});

object.width /= scaleX;
object.height /= scaleY;

if (!this.includeDefaultValues) {
this._removeDefaultValues(object);
}

return object;
},

Expand Down
10 changes: 1 addition & 9 deletions src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,16 +1146,8 @@
* @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: clonedStyles
styles: clone(this.styles, true)
});
}
});
Expand Down
5 changes: 2 additions & 3 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,12 @@
skewY: toFixed(this.skewY, NUM_FRACTION_DIGITS)
};

fabric.util.populateWithProperties(this, object, propertiesToInclude);

if (!this.includeDefaultValues) {
object = this._removeDefaultValues(object);
}

fabric.util.populateWithProperties(this, object, propertiesToInclude);

return object;
},

Expand All @@ -918,7 +918,6 @@
_removeDefaultValues: function(object) {
var prototype = fabric.util.getKlass(object.type).prototype,
stateProperties = prototype.stateProperties;

stateProperties.forEach(function(prop) {
if (object[prop] === prototype[prop]) {
delete object[prop];
Expand Down
11 changes: 2 additions & 9 deletions src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,9 @@
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
var o = extend(this.callSuper('toObject', propertiesToInclude), {
path: this.path.map(function(item) { return item.slice() }),
pathOffset: this.pathOffset
var o = extend(this.callSuper('toObject', ['sourcePath', 'pathOffset'].concat(propertiesToInclude)), {
path: this.path.map(function(item) { return item.slice() })
});
if (this.sourcePath) {
o.sourcePath = this.sourcePath;
}
if (this.transformMatrix) {
o.transformMatrix = this.transformMatrix;
}
return o;
},

Expand Down
5 changes: 1 addition & 4 deletions src/shapes/path_group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,9 @@
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
var o = extend(parentToObject.call(this, propertiesToInclude), {
var o = extend(parentToObject.call(this, ['sourcePath'].concat(propertiesToInclude)), {
paths: invoke(this.getObjects(), 'toObject', propertiesToInclude)
});
if (this.sourcePath) {
o.sourcePath = this.sourcePath;
}
return o;
},

Expand Down
9 changes: 1 addition & 8 deletions src/shapes/rect.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,7 @@
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
var object = extend(this.callSuper('toObject', propertiesToInclude), {
rx: this.get('rx') || 0,
ry: this.get('ry') || 0
});
if (!this.includeDefaultValues) {
this._removeDefaultValues(object);
}
return object;
return this.callSuper('toObject', ['rx', 'ry'].concat(propertiesToInclude));
},

/* _TO_SVG_START_ */
Expand Down
30 changes: 13 additions & 17 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'use strict';

var fabric = global.fabric || (global.fabric = { }),
extend = fabric.util.object.extend,
clone = fabric.util.object.clone,
toFixed = fabric.util.toFixed,
NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS,
Expand Down Expand Up @@ -872,22 +871,19 @@
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
var object = extend(this.callSuper('toObject', propertiesToInclude), {
text: this.text,
fontSize: this.fontSize,
fontWeight: this.fontWeight,
fontFamily: this.fontFamily,
fontStyle: this.fontStyle,
lineHeight: this.lineHeight,
textDecoration: this.textDecoration,
textAlign: this.textAlign,
textBackgroundColor: this.textBackgroundColor,
charSpacing: this.charSpacing
});
if (!this.includeDefaultValues) {
this._removeDefaultValues(object);
}
return object;
var additionalProperties = [
'text',
'fontSize',
'fontWeight',
'fontFamily',
'fontStyle',
'lineHeight',
'textDecoration',
'textAlign',
'textBackgroundColor',
'charSpacing'
].concat(propertiesToInclude);
return this.callSuper('toObject', additionalProperties);
},

/* _TO_SVG_START_ */
Expand Down
4 changes: 1 addition & 3 deletions src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,7 @@
* @return {Object} object representation of an instance
*/
toObject: function(propertiesToInclude) {
return fabric.util.object.extend(this.callSuper('toObject', propertiesToInclude), {
minWidth: this.minWidth
});
return this.callSuper('toObject', ['minWidth'].concat(propertiesToInclude));
}
});
/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
var PATH_DATALESS_JSON = '{"objects":[{"type":"path","originX":"left","originY":"top","left":100,"top":100,"width":200,"height":200,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":"http://example.com/","pathOffset":{"x":200,"y":200}}],"background":""}';
'"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"pathOffset":{"x":200,"y":200},"path":"http://example.com/"}],"background":""}';

var RECT_JSON = '{"objects":[{"type":"rect","originX":"left","originY":"top","left":0,"top":0,"width":10,"height":10,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
Expand Down
4 changes: 2 additions & 2 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
var PATH_DATALESS_JSON = '{"objects":[{"type":"path","originX":"left","originY":"top","left":100,"top":100,"width":200,"height":200,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":"http://example.com/","pathOffset":{"x":200,"y":200}}],"background":""}';
'"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"pathOffset":{"x":200,"y":200},"path":"http://example.com/"}],"background":""}';

var RECT_JSON = '{"objects":[{"type":"rect","originX":"left","originY":"top","left":0,"top":0,"width":10,"height":10,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,' +
Expand All @@ -38,7 +38,7 @@
var RECT_JSON_WITH_PADDING = '{"objects":[{"type":"rect","originX":"left","originY":"top","left":0,"top":0,"width":10,"height":20,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"padding":123,"foo":"bar","rx":0,"ry":0}],"background":""}';
'"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"rx":0,"ry":0,"padding":123,"foo":"bar"}],"background":""}';

function getAbsolutePath(path) {
var isAbsolute = /^https?:/.test(path);
Expand Down