Axiom.Samples.Widget.GetCaptionWidth C# (CSharp) Method

GetCaptionWidth() public static method

Static utility method used to get the width of a caption in a text area.
public static GetCaptionWidth ( String caption, TextArea area ) : Real
caption String
area Axiom.Overlays.Elements.TextArea
return Real
		public static Real GetCaptionWidth( String caption, TextArea area )
		{
			Font font = (Font)FontManager.Instance.GetByName( area.FontName );
			String current = caption;
			Real lineWidth = 0;

			for ( int i = 0; i < current.Length; i++ )
			{
				// be sure to provide a line width in the text area
				if ( current[ i ] == ' ' )
				{
					if ( area.SpaceWidth != 0 )
						lineWidth += area.SpaceWidth;
					else
						lineWidth += font.GetGlyphAspectRatio( ' ' ) * area.CharHeight;
				}
				else if ( current[ i ] == '\n' )
					break;
				// use glyph information to calculate line width
				else
					lineWidth += font.GetGlyphAspectRatio( current[ i ] ) * area.CharHeight;
			}

			return lineWidth;
		}