Fusion.Engine.Graphics.SpriteFont.SpriteFont C# (CSharp) Метод

SpriteFont() публичный Метод

Constrcutor
public SpriteFont ( GraphicsDevice rs, Stream stream ) : System
rs Fusion.Drivers.Graphics.GraphicsDevice
stream Stream
Результат System
		public SpriteFont ( GraphicsDevice rs, Stream stream )
		{
			this.rs	=	rs;

			using (var br = new BinaryReader(stream)) {

				var xml = br.ReadString();
				FontFile input = FontLoader.LoadFromString( xml );

				int numGlyphs	=	input.Chars.Max( ch => ch.ID );

				//	create charInfo and kernings :
				fontInfo.kernings = new Dictionary<Tuple<char,char>, float>();
				fontInfo.charInfo = new SpriteFontInfo.CharInfo[numGlyphs+1];

				//	check one-page bitmap fonts :
				if (input.Pages.Count!=1) {
					throw new GraphicsException("Only one page of font image is supported");
				}

				//	create path for font-image :
				string fontImagePath	=	input.Pages[0].File;

				//	skip two bytes :
				var texData				=	stream.ReadAllBytes();
				fontTexture				=	new UserTexture( rs.Game.RenderSystem, texData, false );
			
				//	Fill structure :
				fontInfo.fontFace		=	input.Info.Face;
				fontInfo.baseLine		=	input.Common.Base;
				fontInfo.lineHeight		=	input.Common.LineHeight;
				fontInfo.scaleWidth		=	input.Common.ScaleW;
				fontInfo.scaleHeight	=	input.Common.ScaleH;

				float scaleWidth = fontInfo.scaleWidth;
				float scaleHeight = fontInfo.scaleHeight;

				//	process character info :
				for ( int i=0; i<input.Chars.Count; i++) {
					FontChar ch = input.Chars[i];

					int id = ch.ID;

					if (id<0) continue;

					int x = ch.X;
					int y = ch.Y;
					int xoffs = ch.XOffset;
					int yoffs = ch.YOffset;
					int w = ch.Width;
					int h = ch.Height;

					fontInfo.charInfo[ ch.ID ].validChar	=	true;
					fontInfo.charInfo[ ch.ID ].xAdvance		=	ch.XAdvance;
					fontInfo.charInfo[ ch.ID ].srcRect		=	new RectangleF(x, y, w, h);
					fontInfo.charInfo[ ch.ID ].dstRect		=	new RectangleF(xoffs, yoffs, w, h);
				}


				var letterHeights = input.Chars
						.Where( ch1 => char.IsUpper( (char)(ch1.ID) ) )
						.Select( ch2 => ch2.Height )
						.OrderBy( h => h )
						.ToList();
				CapHeight	=	letterHeights[ letterHeights.Count/2 ];



				//	process kerning info :
				for ( int i=0; i<input.Kernings.Count; i++) {
					var pair	=	new Tuple<char,char>( (char)input.Kernings[i].First, (char)input.Kernings[i].Second);
					int kerning =	input.Kernings[i].Amount;
					fontInfo.kernings.Add( pair, kerning );
				}

				SpaceWidth	=	MeasureString(" ").Width;
				LineHeight	=	MeasureString(" ").Height;
			}
		}