Template for issues

by Eugene Vilder

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

var canvas = window._canvas = new fabric.Canvas('c');

var t2 = new fabric.Textbox('My text is longer, but I do not want the box to grow, or the text to wrap. I only want the text to fit the available size', {
    width: 200,
    height: 200,
    top: 250,
    left: 5,
    fontSize: 16,
    textAlign: 'center'
});

canvas.add(t2);


t2.on('scaling', function(){
	console.log(this);
  const height = this.getScaledHeight();
  
  this.set({
  	scaleX: 1,
   scaleY: 1,
   width: this.width,
    height,
   clipTo: function(ctx){
   	ctx.rect(
    	-this.width / 2,
      -height / 2,
      this.width,
      height)
   }
  });
});