From f6a7c298b9de1c418d47a0975225832725840ccf Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 1 Jul 2017 16:03:51 +0200 Subject: [PATCH] Textbox can scale as a normal object. (#4052) * enabletextbox-scaling --- src/mixins/textbox_behavior.mixin.js | 22 ++------------ src/shapes/textbox.class.js | 44 ---------------------------- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/src/mixins/textbox_behavior.mixin.js b/src/mixins/textbox_behavior.mixin.js index 96fe601f..16a96397 100644 --- a/src/mixins/textbox_behavior.mixin.js +++ b/src/mixins/textbox_behavior.mixin.js @@ -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; @@ -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 diff --git a/src/shapes/textbox.class.js b/src/shapes/textbox.class.js index bcd52350..6ef8bccb 100644 --- a/src/shapes/textbox.class.js +++ b/src/shapes/textbox.class.js @@ -46,11 +46,6 @@ */ __cachedLines: null, - /** - * Override standard Object class values - */ - lockScalingY: true, - /** * Override standard Object class values */ @@ -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'); @@ -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); }, @@ -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);