예제 #1
0
파일: UiEffect.cs 프로젝트: RugCode/drg-pt
		public UiEffect()
		{			
			m_TextFont = FontMatrix.Read(Helper.ResolvePath(@"~/assets/font-matrix.fm"));
		}
예제 #2
0
		public static FontMatrix Read(string imagePath)
		{
			using (FileStream stream = new FileStream(imagePath, FileMode.Open))
			{
				using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress))
				{
					FontMatrix matrix = new FontMatrix(); 

					using (BinaryReader reader = new BinaryReader(gzip))
					{
						string formatName = reader.ReadString();

						if (formatName != "FontMatrix001")
						{
							throw new Exception("Font Matrix format is incorrect '" + formatName + "'"); 
						}

						matrix.TextureSize = reader.ReadInt32(); 

						matrix.XLarge = new FontResource(); 
						matrix.Large = new FontResource(); 
						matrix.Heading = new FontResource(); 
						matrix.Regular = new FontResource(); 
						matrix.Small = new FontResource(); 
						matrix.Monospaced = new FontResource(); 

						FontResource[] resources = new FontResource[] { matrix.XLarge, matrix.Large, matrix.Heading, matrix.Regular, matrix.Small, matrix.Monospaced };
						reader.ReadInt32();

						for (int i = 0; i < resources.Length; i++)
						{
							resources[i].Read(reader);

							matrix.m_BiggestCharSize[i] = StructHelper.ReadStructure<Rectangle>(reader);

							int count = reader.ReadInt32();

							Dictionary<char, RectangleF> lookup = new Dictionary<char, RectangleF>(count);

							for (int c = 0; c < count; c++)
							{
								char @char = reader.ReadChar(); 

								RectangleF rect = StructHelper.ReadStructure<RectangleF>(reader);
								
								lookup.Add(@char, rect); 
							}

							matrix.m_CharLookup[i] = lookup; 
						}

						int length = reader.ReadInt32(); 

						using (Stream imageStream = new MemoryStream(reader.ReadBytes(length)))
						{
							Bitmap bmp = (Bitmap)Bitmap.FromStream(imageStream);

							// bmp.Save(@"c:\test2.png", ImageFormat.Png);

							matrix.m_Bitmap = bmp;
						}											
					}

					return matrix; 
				}
			}
		}