title: FabricJS fixed size TextBox with dynamic fontsIze (shrink text to fit size)
body: <p>How can I fix the size of a TextBox and dynamically decrease the fontSize if the text gets to large for the TextBox? Yes a similar question exists <a href="https://stackoverflow.com/questions/41279855/fabricjs-textbox-make-the-text-shrink-to-fit">here</a> but it only works for one line of text.</p>
  
  <p>I want to achieve exactly that: (example from the <a href="https://imgflip.com/memegenerator/Star-Wars-Yoda" rel="nofollow noreferrer">imgflip meme editor</a>)<br>
  <a href="https://i.stack.imgur.com/SmaXL.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SmaXL.gif" alt="enter image description here"></a></p>
  
  <p>I have tried following approach: </p>
  
  <pre><code>let text = new fabric.Textbox(box.text, {
      top: box.top,
      left: box.left,
      width: box.width,
  });
  if (text.width &gt; box.width) {
      text.fontSize *= box.width / (text.width + 1);
      text.width = box.width;
  }
  if (text.height &gt; box.height) {
      text.fontSize *= box.height / (text.height + 1);
      text.height = box.height;
  }
  canvas.add(text);
  </code></pre>
  
  <p>This way the fontSize decreases by the ratio of which the width or height of the textbox changed. But this causes the text to get extremely small sometimes because the text won't get wrapped as nicely as it could. The fontSize and the wrapping need to find an optimum somehow. Any ideas? Thanks!</p>