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

Textbox can scale as a normal object. #4052

Merged
merged 2 commits into from
Jul 1, 2017
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
22 changes: 3 additions & 19 deletions src/mixins/textbox_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
lockScalingX, lockScalingY, by, lockScalingFlip, _dim) {

var t = transform.target;
if (t instanceof fabric.Textbox) {
var w = t.width * ((localMouse.x / transform.scaleX) / (t.width + t.strokeWidth));
if (by === 'x' && t instanceof fabric.Textbox) {
var tw = t._getTransformedDimensions().x;
var w = t.width * (localMouse.x / tw);
if (w >= t.getMinWidth()) {
t.set('width', w);
return true;
Expand All @@ -23,23 +24,6 @@
}
};

/**
* Sets controls of this group to the Textbox's special configuration if
* one is present in the group. Deletes _controlsVisibility otherwise, so that
* it gets initialized to default value at runtime.
*/
fabric.Group.prototype._refreshControlsVisibility = function() {
if (typeof fabric.Textbox === 'undefined') {
return;
}
for (var i = this._objects.length; i--;) {
if (this._objects[i] instanceof fabric.Textbox) {
this.setControlsVisibility(fabric.Textbox.getTextboxControlVisibility());
return;
}
}
};

fabric.util.object.extend(fabric.Textbox.prototype, /** @lends fabric.IText.prototype */ {
/**
* @private
Expand Down
44 changes: 0 additions & 44 deletions src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
*/
__cachedLines: null,

/**
* Override standard Object class values
*/
lockScalingY: true,

/**
* Override standard Object class values
*/
Expand All @@ -73,7 +68,6 @@
initialize: function(text, options) {

this.callSuper('initialize', text, options);
this.setControlsVisibility(fabric.Textbox.getTextboxControlVisibility());
this.ctx = this.objectCaching ? this._cacheContext : fabric.util.createCanvasElement().getContext('2d');
// add width to this list of props that effect line wrapping.
this._dimensionAffectingProps.push('width');
Expand Down Expand Up @@ -354,25 +348,6 @@
return newText;
},

/**
* When part of a group, we don't want the Textbox's scale to increase if
* the group's increases. That's why we reduce the scale of the Textbox by
* the amount that the group's increases. This is to maintain the effective
* scale of the Textbox at 1, so that font-size values make sense. Otherwise
* the same font-size value would result in different actual size depending
* on the value of the scale.
* @param {String} key
* @param {*} value
*/
setOnGroup: function(key, value) {
if (key === 'scaleX') {
this.set('scaleX', Math.abs(1 / value));
this.set('width', (this.get('width') * value) /
(typeof this.__oldScaleX === 'undefined' ? 1 : this.__oldScaleX));
this.__oldScaleX = value;
}
},

getMinWidth: function() {
return Math.max(this.minWidth, this.dynamicMinWidth);
},
Expand All @@ -398,23 +373,4 @@
fabric.Textbox.fromObject = function(object, callback) {
return fabric.Object._fromObject('Textbox', object, callback, 'text');
};

/**
* Returns the default controls visibility required for Textboxes.
* @returns {Object}
*/
fabric.Textbox.getTextboxControlVisibility = function() {
return {
tl: false,
tr: false,
br: false,
bl: false,
ml: true,
mt: false,
mr: true,
mb: false,
mtr: true
};
};

})(typeof exports !== 'undefined' ? exports : this);