/// <summary>
/// Calculates text height by ignoring bold style of the font. This will not work with inline bold tags.
/// NOTE: This will not fix occasional new line when text ends right before end.
/// </summary>
/// <param name="content">Text content.</param>
/// <param name="style">Text style.</param>
/// <param name="width">Fixed width of text container.</param>
/// <returns>Returns calculated height of the text.</returns>
public static float CalculateHeight(GUIContent content, GUIStyle style, float width)
{
float height;
// Bold fonts have much higher chance of having one new line to many than normal font.
// There were no issues with missing new lines even with couple of extreme cases. (but extra new lines can occur)
if (style.fontStyle == FontStyle.Bold)
{
style.fontStyle = FontStyle.Normal;
style.wordWrap = true;
style.fixedWidth = width;
style.fixedHeight = 0;
Texture2D t = new Texture2D(1,1);
content.image = t;
style.imagePosition = ImagePosition.ImageLeft;
float min, max;
style.CalcMinMaxWidth(content, out min, out max);
style.clipping = TextClipping.Overflow;
height = style.CalcHeight(content, min);
style.fontStyle = FontStyle.Bold;
}
else
{
height = style.CalcHeight(content, width);
}
return height;
}