コード例 #1
0
 /// <summary>Clones the BitmapCharacter</summary>
 /// <returns>Cloned BitmapCharacter</returns>
 public object Clone()
 {
     BitmapCharacter result = new BitmapCharacter();
     result.X = X;
     result.Y = Y;
     result.Width = Width;
     result.Height = Height;
     result.XOffset = XOffset;
     result.YOffset = YOffset;
     result.XAdvance = XAdvance;
     result.KerningList.AddRange(KerningList);
     return result;
 }
コード例 #2
0
        /// <summary>Parses the FNT file.</summary>
        private void ParseFNTFile()
        {
            StreamReader stream = new StreamReader(m_fntFile);
            string line;
            char[] separators = new char[] { ' ', '=' };
            while ((line = stream.ReadLine()) != null)
            {
                string[] tokens = line.Split(separators);
                if (tokens[0] == "info")
                {
                    // Get rendered size
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        if (tokens[i] == "size")
                        {
                            m_charSet.RenderedSize = int.Parse(tokens[i + 1]);
                        }
                        if (tokens[i] == "face")
                        {
                            m_name = tokens[i + 1].Substring(1,tokens[i+1].Length-2);
                        }
                    }
                }
                else if (tokens[0] == "common")
                {
                    // Fill out BitmapCharacterSet fields
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        if (tokens[i] == "lineHeight")
                        {
                            m_charSet.LineHeight = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "base")
                        {
                            m_charSet.Base = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "scaleW")
                        {
                            m_charSet.Width = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "scaleH")
                        {
                            m_charSet.Height = int.Parse(tokens[i + 1]);
                        }
                    }
                }
                else if (tokens[0] == "page")
                {
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        if (tokens[i] == "file")
                        {
                            m_textureFile = DefaultValues.FontPath+tokens[i + 1].Substring(1, tokens[i + 1].Length - 2);
                        }
                    }
                }
                else if (tokens[0] == "char")
                {
                    // New BitmapCharacter
                    BitmapCharacter character = new BitmapCharacter();
                    char index ;
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        if (tokens[i] == "id")
                        {
                            index = (char)int.Parse(tokens[i + 1]);
                            m_charSet.Characters[index] = character;
                        }
                        else if (tokens[i] == "x")
                        {
                            character.X = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "y")
                        {
                            character.Y = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "width")
                        {
                            character.Width = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "height")
                        {
                            character.Height = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "xoffset")
                        {
                            character.XOffset = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "yoffset")
                        {
                            character.YOffset = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "xadvance")
                        {
                            character.XAdvance = int.Parse(tokens[i + 1]);
                        }
                    }
                }
                else if (tokens[0] == "kerning")
                {
                    // Build kerning list
                    char index;
                    Kerning k = new Kerning();
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        if (tokens[i] == "first")
                        {
                            index = (char)int.Parse(tokens[i + 1]);
                            ((BitmapCharacter)m_charSet.Characters[index]).KerningList.Add(k);
                        }
                        else if (tokens[i] == "second")
                        {
                            k.Second = int.Parse(tokens[i + 1]);
                        }
                        else if (tokens[i] == "amount")
                        {
                            k.Amount = int.Parse(tokens[i + 1]);
                        }
                    }

                }
            }
            stream.Close();
        }