Template for issues
HTML
<script src="https://rawgithub.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width="600" height="600"></canvas>
CSS
canvas {
border: 1px solid #999;
}
JavaScript
(function() {
fabric.Paragraph = fabric.util.createClass(fabric.Textbox, {
type: 'paragraph',
initialize: function(element, options) {
this.set({
autoHeight: options.autoHeight === undefined ? true : options.autoHeight,
});
this.callSuper('initialize', element, options);
// alert(options.autoHeight);
this.set({
clipTo: function(ctx){
ctx.rect(-this.width / 2, -this.height / 2,this.width, this.height);
}.bind(this)
});
this.on('scaling', function(){
this.set({
scaleX: 1,
scaleY: 1,
clipTo: function(ctx){
ctx.rect(-this.width / 2, -this.height / 2,this.width, this.height);
}
});
});
},
calcTextHeight: function() {
if (!this.autoHeight) {
return this.height;
} else {
var lineHeight, height = 0;
for (var i = 0, len = this._textLines.length; i < len; i++) {
lineHeight = this.getHeightOfLine(i);
height += i === len - 1 ? lineHeight / this.lineHeight : lineHeight;
}
return height;
}
},
});
var setObjectScaleOverridden = fabric.Canvas.prototype._setObjectScale;
fabric.Canvas.prototype._setObjectScale = function(localMouse, transform, lockScalingX, lockScalingY, by, lockScalingFlip, _dim) {
var t = transform.target;
if (by === "equally" && t instanceof fabric.Paragraph) {
var tw = t._getTransformedDimensions().x;
var w = t.width * (localMouse.x / tw);
var th = t._getTransformedDimensions().y;
var h = t.height * (localMouse.y / th);
t.set('width', w);
t.set('height', h);
return true;
} else if (by === "x" && t instanceof fabric.Paragraph) {
var xtw = t._getTransformedDimensions().x;
var xw = t.width * (localMouse.x / xtw);
t.set('width', xw);
return true;
} else if (by...