Axiom.Samples.Widget.FitCaptionToArea C# (CSharp) Метод

FitCaptionToArea() публичный статический Метод

Static utility method to cut off a string to fit in a text area.
public static FitCaptionToArea ( String caption, TextArea area, Real maxWidth ) : void
caption String
area Axiom.Overlays.Elements.TextArea
maxWidth Real
Результат void
		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;
		}