示例#1
0
        public static FontInfo Parse(string path)
        {
            FontInfo fontInfo = new FontInfo();

            StreamReader reader = new StreamReader(path);

            string line;
            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split( ' ' );

                if (tokens[0] == "common")
                {
                    fontInfo.lineHeight = int.Parse( FindKeyValue(tokens, "lineHeight") );
                    fontInfo.scaleW = int.Parse( FindKeyValue(tokens, "scaleW") );
                    fontInfo.scaleH = int.Parse( FindKeyValue(tokens, "scaleH") );
                    int pages = int.Parse( FindKeyValue(tokens, "pages") );
                    if (pages != 1)
                    {
                        Debug.LogError("Only one page supported in font. Please change the setting and re-export.");
                        return null;
                    }
                    fontInfo.numPages = pages;
                    fontInfo.texturePaths = new string[pages];
                    for (int i = 0 ; i < pages; ++i)
                        fontInfo.texturePaths[i] = string.Empty;
                }
                else if (tokens[0] == "page")
                {
                    int id = int.Parse(FindKeyValue(tokens, "id"));
                    string file = FindKeyValue(tokens, "file");
                    if (file[0] == '"' && file[file.Length - 1] == '"')
                        file = file.Substring(1, file.Length - 2);
                    fontInfo.texturePaths[id] = file;
                }
                else if (tokens[0] == "char")
                {
                    FontChar thisChar = new FontChar();
                    thisChar.id = int.Parse(FindKeyValue(tokens, "id"));
                    thisChar.x = int.Parse(FindKeyValue(tokens, "x"));
                    thisChar.y = int.Parse(FindKeyValue(tokens, "y"));
                    thisChar.width = int.Parse(FindKeyValue(tokens, "width"));
                    thisChar.height = int.Parse(FindKeyValue(tokens, "height"));
                    thisChar.xoffset = int.Parse(FindKeyValue(tokens, "xoffset"));
                    thisChar.yoffset = int.Parse(FindKeyValue(tokens, "yoffset"));
                    thisChar.xadvance = int.Parse(FindKeyValue(tokens, "xadvance"));
                    fontInfo.chars.Add(thisChar);
                }
                else if (tokens[0] == "kerning")
                {
                    FontKerning thisKerning = new FontKerning();
                    thisKerning.first = int.Parse(FindKeyValue(tokens, "first"));
                    thisKerning.second = int.Parse(FindKeyValue(tokens, "second"));
                    thisKerning.amount = int.Parse(FindKeyValue(tokens, "amount"));
                    fontInfo.kernings.Add(thisKerning);
                }
            }
            reader.Close();

            return fontInfo;
        }
示例#2
0
        public static FontInfo Parse(string path)
        {
            FontInfo fontInfo = new FontInfo();

            StreamReader reader = new StreamReader(path);

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(' ');

                if (tokens[0] == "common")
                {
                    fontInfo.lineHeight = int.Parse(FindKeyValue(tokens, "lineHeight"));
                    fontInfo.scaleW     = int.Parse(FindKeyValue(tokens, "scaleW"));
                    fontInfo.scaleH     = int.Parse(FindKeyValue(tokens, "scaleH"));
                    int pages = int.Parse(FindKeyValue(tokens, "pages"));
                    if (pages != 1)
                    {
                        Debug.LogError("Only one page supported in font. Please change the setting and re-export.");
                        return(null);
                    }
                    fontInfo.numPages     = pages;
                    fontInfo.texturePaths = new string[pages];
                    for (int i = 0; i < pages; ++i)
                    {
                        fontInfo.texturePaths[i] = string.Empty;
                    }
                }
                else if (tokens[0] == "page")
                {
                    int    id   = int.Parse(FindKeyValue(tokens, "id"));
                    string file = FindKeyValue(tokens, "file");
                    if (file[0] == '"' && file[file.Length - 1] == '"')
                    {
                        file = file.Substring(1, file.Length - 2);
                    }
                    fontInfo.texturePaths[id] = file;
                }
                else if (tokens[0] == "char")
                {
                    FontChar thisChar = new FontChar();
                    thisChar.id       = int.Parse(FindKeyValue(tokens, "id"));
                    thisChar.x        = int.Parse(FindKeyValue(tokens, "x"));
                    thisChar.y        = int.Parse(FindKeyValue(tokens, "y"));
                    thisChar.width    = int.Parse(FindKeyValue(tokens, "width"));
                    thisChar.height   = int.Parse(FindKeyValue(tokens, "height"));
                    thisChar.xoffset  = int.Parse(FindKeyValue(tokens, "xoffset"));
                    thisChar.yoffset  = int.Parse(FindKeyValue(tokens, "yoffset"));
                    thisChar.xadvance = int.Parse(FindKeyValue(tokens, "xadvance"));
                    fontInfo.chars.Add(thisChar);
                }
                else if (tokens[0] == "kerning")
                {
                    FontKerning thisKerning = new FontKerning();
                    thisKerning.first  = int.Parse(FindKeyValue(tokens, "first"));
                    thisKerning.second = int.Parse(FindKeyValue(tokens, "second"));
                    thisKerning.amount = int.Parse(FindKeyValue(tokens, "amount"));
                    fontInfo.kernings.Add(thisKerning);
                }
            }
            reader.Close();

            return(fontInfo);
        }