If you need something more precise, I found a solution from viewing docs , and this tip .
Both of them work great for me with single-line multi-line hyphenation (only for text hyphenation and \ n) and multi-line hyphenation (just \ n).
Short penultimate version (do not use this):
var totalLines = textField.bottomScrollV - textField.scrollV + textField.maxScrollV; var metrics = textField.getLineMetrics(0); var gutter = 2; var actualHeight = (metrics.ascent + metrics.descent) * totalLines + (totalLines - 1) * metrics.leading + 2 * gutter;
A longer version where the rows have different metrics (use this):
var gutter = 2; var totalLines = textField.bottomScrollV - textField.scrollV + textField.maxScrollV; var actualHeight = 0; var prevLeading = 0; for (var i = 0; i < totalLines; i += 1) { var metrics = textField.getLineMetrics(i); actualHeight += metrics.ascent + metrics.descent + prevLeading; prevLeading = metrics.leading; } actualHeight += 2 * gutter;
For one test, lines with an embedded image where textField height gives me 32, textHeight gives me 39, the calculated height (actualHeight above) is 34. For a multi-line test where the height is 97.20, textHeight is 23.79, actualHeight 97.15. This actual height includes a gutter on both sides, but removes the final lead, if any.
source share