title: Calculate StyledText height using text content
body: <p>Given a <code>StyledText</code>, initializied with <code>SWT.MULTI</code> and <code>SWT.WRAP</code>, I need to calculate the appropriate height hint based on the appropriate lines count for the content.</p>
  <p>In this image you can see how the editor is resized when the content changes</p>
  <p><a href="https://i.stack.imgur.com/gUqsw.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gUqsw.gif" alt="enter image description here" /></a></p>
  <p>The code that calculates the lines to display is the following</p>
  <pre><code>private int calcRealLinesCount() {
    final int componentWidth = styledText.getSize().x;
    final int dumbLinesCount = styledText.getLineCount();
    int realLinesCount = 0;
  
    for (int i = 0; i &lt; dumbLinesCount; i++) {
      final String lineText = styledText.getLine(i);
      final Point lineTextExtent = styledTextGc.textExtent(lineText);
      final double lines = lineTextExtent.x / (double) componentWidth;
      realLinesCount += (int) Math.max(1D, Math.ceil(lines));
    }
  
    return Math.max(dumbLinesCount, realLinesCount);
  }
  </code></pre>
  <p>The lines count is then used to get the appropriate height</p>
  <pre><code>((GridData) layoutData).heightHint = realLinesCount * fontHeight;
  </code></pre>
  <p>However, this code <strong>does not consider word wraps</strong>, and I cannot think of a way to do it.<br />
  Any ideas? Could I do this in a different way?</p>