void LoadFont(PackageItem item)
{
BitmapFont font = item.bitmapFont;
string str = _descPack[item.id + ".fnt"];
string[] arr = str.Split('\n');
int cnt = arr.Length;
Dictionary<string, string> kv = new Dictionary<string, string>();
NTexture mainTexture = null;
Vector2 atlasOffset = new Vector2();
bool ttf = false;
int size = 0;
int xadvance = 0;
bool resizable = false;
bool canTint = false;
bool hasFullChannel = false;
int lineHeight = 0;
BitmapFont.BMGlyph bg = null;
char[] splitter0 = new char[] { ' ' };
char[] splitter1 = new char[] { '=' };
for (int i = 0; i < cnt; i++)
{
str = arr[i];
if (str.Length == 0)
continue;
str = str.Trim();
string[] arr2 = str.Split(splitter0, StringSplitOptions.RemoveEmptyEntries);
for (int j = 1; j < arr2.Length; j++)
{
string[] arr3 = arr2[j].Split(splitter1, StringSplitOptions.RemoveEmptyEntries);
if (arr3.Length >= 2)
kv[arr3[0]] = arr3[1];
}
str = arr2[0];
if (str == "char")
{
bg = new BitmapFont.BMGlyph();
int bx = 0, by = 0;
if (kv.TryGetValue("x", out str))
bx = int.Parse(str);
if (kv.TryGetValue("y", out str))
by = int.Parse(str);
if (kv.TryGetValue("xoffset", out str))
bg.offsetX = int.Parse(str);
if (kv.TryGetValue("yoffset", out str))
bg.offsetY = int.Parse(str);
if (kv.TryGetValue("width", out str))
bg.width = int.Parse(str);
if (kv.TryGetValue("height", out str))
bg.height = int.Parse(str);
if (kv.TryGetValue("xadvance", out str))
bg.advance = int.Parse(str);
if (kv.TryGetValue("chnl", out str))
{
bg.channel = int.Parse(str);
if (bg.channel == 1)
bg.channel = 3;
else if (bg.channel == 2)
bg.channel = 2;
else if (bg.channel == 3)
bg.channel = 1;
else
hasFullChannel = true;
}
else
hasFullChannel = true;
if (!ttf)
{
if (kv.TryGetValue("img", out str))
{
PackageItem charImg;
if (_itemsById.TryGetValue(str, out charImg))
{
GetItemAsset(charImg);
bg.uvRect = charImg.texture.uvRect;
if (mainTexture == null)
mainTexture = charImg.texture.root;
bg.width = charImg.texture.width;
bg.height = charImg.texture.height;
}
}
}
else
{
Rect region = new Rect(bx + atlasOffset.x, by + atlasOffset.y, bg.width, bg.height);
bg.uvRect = new Rect(region.x / mainTexture.width, 1 - region.yMax / mainTexture.height,
region.width / mainTexture.width, region.height / mainTexture.height);
}
if (ttf)
bg.lineHeight = lineHeight;
else
{
if (bg.advance == 0)
{
if (xadvance == 0)
bg.advance = bg.offsetX + bg.width;
else
bg.advance = xadvance;
}
bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
if (bg.lineHeight < size)
bg.lineHeight = size;
}
int ch = int.Parse(kv["id"]);
font.AddChar((char)ch, bg);
}
else if (str == "info")
{
if (kv.TryGetValue("face", out str))
{
ttf = true;
canTint = true;
AtlasSprite sprite;
if (_sprites.TryGetValue(item.id, out sprite))
{
atlasOffset = new Vector2(sprite.rect.x, sprite.rect.y);
PackageItem atlasItem = _itemsById[sprite.atlas];
mainTexture = (NTexture)GetItemAsset(atlasItem);
}
}
if (kv.TryGetValue("size", out str))
size = int.Parse(str);
if (kv.TryGetValue("resizable", out str))
resizable = str == "true";
if (kv.TryGetValue("colored", out str))
canTint = str == "true";
if (size == 0)
size = lineHeight;
else if (lineHeight == 0)
lineHeight = size;
}
else if (str == "common")
{
if (kv.TryGetValue("lineHeight", out str))
lineHeight = int.Parse(str);
if (kv.TryGetValue("xadvance", out str))
xadvance = int.Parse(str);
}
}
if (size == 0 && bg != null)
size = bg.height;
font.hasChannel = ttf;
font.canTint = canTint;
font.size = size;
font.resizable = resizable;
font.mainTexture = mainTexture;
if (!ttf || hasFullChannel)
font.shader = ShaderConfig.imageShader;
}