Example #1
0
        static Info ParseBMFontText(string path)
        {
            Info fontInfo = new Info();

            System.IO.FileInfo finfo = new System.IO.FileInfo(path);
            System.IO.StreamReader reader = finfo.OpenText();
            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)
                    {
                        EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                        return null;
                    }
                }
                else if (tokens[0] == "char")
                {
                    Char thisChar = new Char();
                    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")
                {
                    Kerning thisKerning = new Kerning();
                    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;
        }
Example #2
0
        static Info ParseBMFontXml(XmlDocument doc)
        {
            Info fontInfo = new Info();

            XmlNode nodeCommon = doc.SelectSingleNode("/font/common");
            fontInfo.scaleW = ReadIntAttribute(nodeCommon, "scaleW");
            fontInfo.scaleH = ReadIntAttribute(nodeCommon, "scaleH");
            fontInfo.lineHeight = ReadIntAttribute(nodeCommon, "lineHeight");
            int pages = ReadIntAttribute(nodeCommon, "pages");
            if (pages != 1)
            {
                EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                return null;
            }

            foreach (XmlNode node in doc.SelectNodes(("/font/chars/char")))
            {
                Char thisChar = new Char();
                thisChar.id = ReadIntAttribute(node, "id");
                thisChar.x = ReadIntAttribute(node, "x");
                thisChar.y = ReadIntAttribute(node, "y");
                thisChar.width = ReadIntAttribute(node, "width");
                thisChar.height = ReadIntAttribute(node, "height");
                thisChar.xoffset = ReadIntAttribute(node, "xoffset");
                thisChar.yoffset = ReadIntAttribute(node, "yoffset");
                thisChar.xadvance = ReadIntAttribute(node, "xadvance");

                thisChar.texOverride = false;

                fontInfo.chars.Add(thisChar);
            }

            foreach (XmlNode node in doc.SelectNodes("/font/kernings/kerning"))
            {
                Kerning thisKerning = new Kerning();
                thisKerning.first = ReadIntAttribute(node, "first");
                thisKerning.second = ReadIntAttribute(node, "second");
                thisKerning.amount = ReadIntAttribute(node, "amount");

                fontInfo.kernings.Add(thisKerning);
            }

            return fontInfo;
        }
		public static Info Parse(string path)
		{
			XmlDocument doc = new XmlDocument();
			doc.Load(path);
			Info fontInfo = new Info();
			
	        XmlNode nodeCommon = doc.SelectSingleNode("/font/common");
			fontInfo.scaleW = ReadIntAttribute(nodeCommon, "scaleW");
			fontInfo.scaleH = ReadIntAttribute(nodeCommon, "scaleH");
			fontInfo.lineHeight = ReadIntAttribute(nodeCommon, "lineHeight");
			int pages = ReadIntAttribute(nodeCommon, "pages");
			if (pages != 1)
			{
				EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
				return null;
			}
			fontInfo.numPages = pages;
			fontInfo.texturePaths = new string[pages];
			for (int i = 0; i < pages; ++i) fontInfo.texturePaths[i] = string.Empty;

			foreach (XmlNode node in doc.SelectNodes("/font/pages/page"))
			{
				int id = ReadIntAttribute(node, "id");
				fontInfo.texturePaths[id] = ReadStringAttribute(node, "file");
			}
	
			foreach (XmlNode node in doc.SelectNodes(("/font/chars/char")))
			{
				Char thisChar = new Char();
				thisChar.id = ReadIntAttribute(node, "id");
	            thisChar.x = ReadIntAttribute(node, "x");
	            thisChar.y = ReadIntAttribute(node, "y");
	            thisChar.width = ReadIntAttribute(node, "width");
	            thisChar.height = ReadIntAttribute(node, "height");
	            thisChar.xoffset = ReadIntAttribute(node, "xoffset");
	            thisChar.yoffset = ReadIntAttribute(node, "yoffset");
	            thisChar.xadvance = ReadIntAttribute(node, "xadvance");
				
				thisChar.texOverride = false;
				
				if (thisChar.id == -1) thisChar.id = 0;
				fontInfo.chars.Add(thisChar);
			}
			
			foreach (XmlNode node in doc.SelectNodes("/font/kernings/kerning"))
			{
				Kerning thisKerning = new Kerning();
				thisKerning.first = ReadIntAttribute(node, "first");
				thisKerning.second = ReadIntAttribute(node, "second");
				thisKerning.amount = ReadIntAttribute(node, "amount");
				
				fontInfo.kernings.Add(thisKerning);
			}
	
			return fontInfo;
		}
		public static Info Parse(string path)
		{
			Info fontInfo = new Info();
			
			System.IO.FileInfo finfo = new System.IO.FileInfo(path);
			System.IO.StreamReader reader = finfo.OpenText();
			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)
					{
						EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
						return null;
					}
					fontInfo.numPages = pages;
					if (FindKeyValue(tokens, "packed") != "")
						fontInfo.isPacked = int.Parse(FindKeyValue(tokens, "packed")) != 0;
					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);
					}
					else if (file[0] == '"' && file[file.Length - 1] != '"') {
						System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(line, "file[\\s]*=[\\s]*\"([^\"]*)\"");
						try {
							file = match.Groups[1].Value;
						}
						catch {
							file = "";
						}
					}
					fontInfo.texturePaths[id] = file;
				}
				else if (tokens[0] == "char")
				{
					Char thisChar = new Char();
					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"));
					if (fontInfo.isPacked)
					{
						int chnl = int.Parse(FindKeyValue(tokens, "chnl"));
						thisChar.channel = (int)Mathf.Round(Mathf.Log(chnl) / Mathf.Log(2));
					}
					if (thisChar.id == -1) thisChar.id = 0;
					fontInfo.chars.Add(thisChar);
				}
				else if (tokens[0] == "kerning")
				{
					Kerning thisKerning = new Kerning();
					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;
		}		
Example #5
0
        public static Info Parse(string path)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            Info fontInfo = new Info();

            XmlNode nodeCommon = doc.SelectSingleNode("/font/common");

            fontInfo.scaleW     = ReadIntAttribute(nodeCommon, "scaleW");
            fontInfo.scaleH     = ReadIntAttribute(nodeCommon, "scaleH");
            fontInfo.lineHeight = ReadIntAttribute(nodeCommon, "lineHeight");
            int pages = ReadIntAttribute(nodeCommon, "pages");

            if (pages != 1)
            {
                EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                return(null);
            }
            fontInfo.numPages     = pages;
            fontInfo.texturePaths = new string[pages];
            for (int i = 0; i < pages; ++i)
            {
                fontInfo.texturePaths[i] = string.Empty;
            }

            foreach (XmlNode node in doc.SelectNodes("/font/pages/page"))
            {
                int id = ReadIntAttribute(node, "id");
                fontInfo.texturePaths[id] = ReadStringAttribute(node, "file");
            }

            foreach (XmlNode node in doc.SelectNodes(("/font/chars/char")))
            {
                Char thisChar = new Char();
                thisChar.id       = ReadIntAttribute(node, "id");
                thisChar.x        = ReadIntAttribute(node, "x");
                thisChar.y        = ReadIntAttribute(node, "y");
                thisChar.width    = ReadIntAttribute(node, "width");
                thisChar.height   = ReadIntAttribute(node, "height");
                thisChar.xoffset  = ReadIntAttribute(node, "xoffset");
                thisChar.yoffset  = ReadIntAttribute(node, "yoffset");
                thisChar.xadvance = ReadIntAttribute(node, "xadvance");

                thisChar.texOverride = false;

                if (thisChar.id == -1)
                {
                    thisChar.id = 0;
                }
                fontInfo.chars.Add(thisChar);
            }

            foreach (XmlNode node in doc.SelectNodes("/font/kernings/kerning"))
            {
                Kerning thisKerning = new Kerning();
                thisKerning.first  = ReadIntAttribute(node, "first");
                thisKerning.second = ReadIntAttribute(node, "second");
                thisKerning.amount = ReadIntAttribute(node, "amount");

                fontInfo.kernings.Add(thisKerning);
            }

            return(fontInfo);
        }
Example #6
0
        public static Info Parse(string path)
        {
            Info fontInfo = new Info();

            System.IO.FileInfo     finfo  = new System.IO.FileInfo(path);
            System.IO.StreamReader reader = finfo.OpenText();
            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)
                    {
                        EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                        return(null);
                    }
                    fontInfo.numPages = pages;
                    if (FindKeyValue(tokens, "packed") != "")
                    {
                        fontInfo.isPacked = int.Parse(FindKeyValue(tokens, "packed")) != 0;
                    }
                    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")
                {
                    Char thisChar = new Char();
                    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"));
                    if (fontInfo.isPacked)
                    {
                        int chnl = int.Parse(FindKeyValue(tokens, "chnl"));
                        thisChar.channel = (int)Mathf.Round(Mathf.Log(chnl) / Mathf.Log(2));
                    }
                    if (thisChar.id == -1)
                    {
                        thisChar.id = 0;
                    }
                    fontInfo.chars.Add(thisChar);
                }
                else if (tokens[0] == "kerning")
                {
                    Kerning thisKerning = new Kerning();
                    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);
        }
        public static Info Parse(string path)
        {
            Info fontInfo = new Info();

            System.IO.FileInfo finfo = new System.IO.FileInfo(path);
            System.IO.StreamReader reader = finfo.OpenText();
            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)
                    {
                        EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                        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")
                {
                    Char thisChar = new Char();
                    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")
                {
                    Kerning thisKerning = new Kerning();
                    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;
        }