remove unused function in staticCanvas (#3313)

* remove unused function in static
* fixed svg export
This commit is contained in:
Andrea Bogazzi 2016-10-02 12:12:42 +02:00 committed by GitHub
parent cd4c465f4c
commit b46c5b4ca3
5 changed files with 83 additions and 98 deletions

View file

@ -1516,6 +1516,66 @@
}
},
/**
* @private
*/
_toObject: function(instance, methodName, propertiesToInclude) {
//If the object is part of the current selection group, it should
//be transformed appropriately
//i.e. it should be serialised as it would appear if the selection group
//were to be destroyed.
var originalProperties = this._realizeGroupTransformOnObject(instance),
object = this.callSuper('_toObject', instance, methodName, propertiesToInclude);
//Undo the damage we did by changing all of its properties
this._unwindGroupTransformOnObject(instance, originalProperties);
return object;
},
/**
* Realises an object's group transformation on it
* @private
* @param {fabric.Object} [instance] the object to transform (gets mutated)
* @returns the original values of instance which were changed
*/
_realizeGroupTransformOnObject: function(instance) {
var layoutProps = ['angle', 'flipX', 'flipY', 'height', 'left', 'scaleX', 'scaleY', 'top', 'width'];
if (instance.group && instance.group === this.getActiveGroup()) {
//Copy all the positionally relevant properties across now
var originalValues = {};
layoutProps.forEach(function(prop) {
originalValues[prop] = instance[prop];
});
this.getActiveGroup().realizeTransform(instance);
return originalValues;
}
else {
return null;
}
},
/**
* Restores the changed properties of instance
* @private
* @param {fabric.Object} [instance] the object to un-transform (gets mutated)
* @param {Object} [originalValues] the original values of instance, as returned by _realizeGroupTransformOnObject
*/
_unwindGroupTransformOnObject: function(instance, originalValues) {
if (originalValues) {
instance.set(originalValues);
}
},
/**
* @private
*/
_setSVGObject: function(markup, instance, reviver) {
var originalProperties;
//If the object is in a selection group, simulate what would happen to that
//object when the group is deselected
originalProperties = this._realizeGroupTransformOnObject(instance);
this.callSuper('_setSVGObject', markup, instance, reviver);
this._unwindGroupTransformOnObject(instance, originalProperties);
},
});
// copying static properties manually to work around Opera's bug,

View file

@ -117,8 +117,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
origHeight = this.getHeight(),
scaledWidth = origWidth * multiplier,
scaledHeight = origHeight * multiplier,
activeObject = this.getActiveObject(),
activeGroup = this.getActiveGroup(),
activeObject = this._activeObject,
activeGroup = this._activeGroup,
zoom = this.getZoom(),
newZoom = zoom * multiplier / fabric.devicePixelRatio;

View file

@ -193,8 +193,7 @@
* @chainable
*/
drawSelectionBackground: function(ctx) {
if (!this.selectionBackgroundColor || this.group
|| this !== this.canvas.getActiveObject()) {
if (!this.selectionBackgroundColor || this.group || !this.active) {
return this;
}
ctx.save();

View file

@ -668,10 +668,11 @@
* @chainable true
*/
setViewportTransform: function (vpt) {
var activeGroup = this.getActiveGroup();
var activeGroup = this._activeGroup, object;
this.viewportTransform = vpt;
for (var i = 0, len = this._objects.length; i < len; i++) {
this._objects[i].setCoords();
object = this._objects[i];
object.group || object.setCoords();
}
if (activeGroup) {
activeGroup.setCoords();
@ -744,22 +745,6 @@
return this.lowerCanvasEl;
},
/**
* Returns currently selected object, if any
* @return {fabric.Object}
*/
getActiveObject: function() {
return null;
},
/**
* Returns currently selected group of object, if any
* @return {fabric.Group}
*/
getActiveGroup: function() {
return null;
},
/**
* @private
* @param {fabric.Object} obj Object that was added
@ -849,27 +834,19 @@
ctx.transform.apply(ctx, this.viewportTransform);
this._renderObjects(ctx, objects);
ctx.restore();
if (!this.controlsAboveOverlay && this.interactive) {
if (!this.controlsAboveOverlay && this.drawControls) {
this.drawControls(ctx);
}
if (this.clipTo) {
ctx.restore();
}
this._renderOverlay(ctx);
if (this.controlsAboveOverlay && this.interactive) {
if (this.controlsAboveOverlay && this.drawControls) {
this.drawControls(ctx);
}
this.fire('after:render');
},
/**
* dummy function for organization purpouse.
* @private
*/
drawControls: function() {
// NOOP
},
/**
* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
@ -1100,56 +1077,13 @@
instance.includeDefaultValues = false;
}
//If the object is part of the current selection group, it should
//be transformed appropriately
//i.e. it should be serialised as it would appear if the selection group
//were to be destroyed.
var originalProperties = this._realizeGroupTransformOnObject(instance),
object = instance[methodName](propertiesToInclude);
var object = instance[methodName](propertiesToInclude);
if (!this.includeDefaultValues) {
instance.includeDefaultValues = originalValue;
}
//Undo the damage we did by changing all of its properties
this._unwindGroupTransformOnObject(instance, originalProperties);
return object;
},
/**
* Realises an object's group transformation on it
* @private
* @param {fabric.Object} [instance] the object to transform (gets mutated)
* @returns the original values of instance which were changed
*/
_realizeGroupTransformOnObject: function(instance) {
var layoutProps = ['angle', 'flipX', 'flipY', 'height', 'left', 'scaleX', 'scaleY', 'top', 'width'];
if (instance.group && instance.group === this.getActiveGroup()) {
//Copy all the positionally relevant properties across now
var originalValues = {};
layoutProps.forEach(function(prop) {
originalValues[prop] = instance[prop];
});
this.getActiveGroup().realizeTransform(instance);
return originalValues;
}
else {
return null;
}
},
/**
* Restores the changed properties of instance
* @private
* @param {fabric.Object} [instance] the object to un-transform (gets mutated)
* @param {Object} [originalValues] the original values of instance, as returned by _realizeGroupTransformOnObject
*/
_unwindGroupTransformOnObject: function(instance, originalValues) {
if (originalValues) {
instance.set(originalValues);
}
},
/**
* @private
*/
@ -1307,20 +1241,24 @@
* @private
*/
_setSVGObjects: function(markup, reviver) {
var instance, originalProperties;
var instance;
for (var i = 0, objects = this.getObjects(), len = objects.length; i < len; i++) {
instance = objects[i];
if (instance.excludeFromExport) {
continue;
}
//If the object is in a selection group, simulate what would happen to that
//object when the group is deselected
originalProperties = this._realizeGroupTransformOnObject(instance);
markup.push(instance.toSVG(reviver));
this._unwindGroupTransformOnObject(instance, originalProperties);
this._setSVGObject(markup, instance, reviver);
}
},
/**
* push single object svg representation in the markup
* @private
*/
_setSVGObject: function(markup, instance, reviver) {
markup.push(instance.toSVG(reviver));
},
/**
* @private
*/
@ -1372,7 +1310,7 @@
if (!object) {
return this;
}
var activeGroup = this.getActiveGroup ? this.getActiveGroup() : null,
var activeGroup = this._activeGroup,
i, obj, objs;
if (object === activeGroup) {
objs = activeGroup._objects;
@ -1400,7 +1338,7 @@
if (!object) {
return this;
}
var activeGroup = this.getActiveGroup ? this.getActiveGroup() : null,
var activeGroup = this._activeGroup,
i, obj, objs;
if (object === activeGroup) {
objs = activeGroup._objects;
@ -1428,7 +1366,7 @@
if (!object) {
return this;
}
var activeGroup = this.getActiveGroup ? this.getActiveGroup() : null,
var activeGroup = this._activeGroup,
i, obj, idx, newIdx, objs;
if (object === activeGroup) {
@ -1496,7 +1434,7 @@
if (!object) {
return this;
}
var activeGroup = this.getActiveGroup ? this.getActiveGroup() : null,
var activeGroup = this._activeGroup,
i, obj, idx, newIdx, objs;
if (object === activeGroup) {

View file

@ -1382,18 +1382,6 @@
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform;
});
test('getActiveObject', function() {
ok(typeof canvas.getActiveObject == 'function');
var activeObject = canvas.getActiveObject();
equal(activeObject, null, 'should return null');
});
test('getActiveGroup', function() {
ok(typeof canvas.getActiveGroup == 'function');
var activeGroup = canvas.getActiveGroup();
equal(activeGroup, null, 'should return null');
});
test('getContext', function() {
ok(typeof canvas.getContext == 'function');
var context = canvas.getContext();