public void Load(Bitmap fontImage, byte[] format)
{
var ser = new Xml.Serialization.XmlSerializer(typeof(font));
using (var str = new System.IO.MemoryStream(format))
{
var font = (font)ser.Deserialize(str);
textureList = new Dictionary<int, BitmapChar>();
for (int i = 0; i < font.chars.Length; i++)
{
var fChar = font.chars[i];
var bChar = new BitmapChar();
bChar.Id = fChar.id[0];
bChar.Advance = fChar.advance;
var charRect = fChar.rect.Split(' ');
int charX = Convert.ToInt32(charRect[0]);
int charY = Convert.ToInt32(charRect[1]);
int charW = Convert.ToInt32(charRect[2]);
int charH = Convert.ToInt32(charRect[3]);
var offset = fChar.offset.Split(' ');
bChar.OffsetX = Convert.ToInt32(offset[0]);
bChar.OffsetY = Convert.ToInt32(offset[1]);
bChar.Texture = new Bitmap(charW, charH);
bChar.Texture.uTexture.name = (char)bChar.Id + "_GlyphTexture";
if (charW > 0 && charH > 0)
{
}
if (charW > 0 && charH > 0)
for (int y = charY, by = 0; by < charH; y++, by++)
for (int x = charX, bx = 0; bx < charW; x++, bx++)
{
var c1 = fontImage.GetPixel(x, y);
bChar.Texture.SetPixel(bx, by, c1);
}
bChar.Texture.Apply();
textureList.Add(bChar.Id, bChar);
}
}
Loaded = true;
}