public static void FitCaptionToArea( String caption, TextArea area, Real maxWidth )
{
Font f = (Font)FontManager.Instance.GetByName( area.FontName );
String s = caption;
int nl = s.IndexOf( '\n' );
if ( nl != -1 )
s = s.Substring( 0, nl );
Real width = 0;
for ( int i = 0; i < s.Length; i++ )
{
if ( s[ i ] == ' ' && area.SpaceWidth != 0 )
width += area.SpaceWidth;
else
width += f.GetGlyphAspectRatio( s[ i ] ) * area.CharHeight;
if ( width > maxWidth )
{
s = s.Substring( 0, i );
break;
}
}
area.Text = s;
}