예제 #1
0
        /// <summary>
        /// 缓存字形
        /// </summary>
        /// <param name="charArray">需要缓存的字符</param>
        public void Cache(char[] charArray)
        {
            List <char> chars = charArray.ToList();

            for (int i = 0; i < chars.Count; i++)
            {
                if (Glyphs.ContainsKey(chars[i]) || chars.IndexOf(chars[i]) < i || chars[i] == ' ')
                {
                    chars.RemoveAt(i);
                    i--;
                }
            }
            if (chars.Count == 0)
            {
                return;
            }
            Glyph[] glyphArray = font.GetGlyphsFromCodepoint(height, chars.ToCodePointArray(), 1f, 1f);
            for (int i = 0; i < chars.Count; i++)
            {
                if (glyphArray[i].texture == null && glyphArray[i].Width != 0)
                {
                    glyphArray[i].texture = FontHelper.ByteDataToTexture2D(graphicsDevice, glyphArray[i].bitmap,
                                                                           glyphArray[i].Width, glyphArray[i].Height);
                    glyphArray[i].bitmap = new byte[0];
                }
                Glyphs.Add(chars[i], glyphArray[i]);
            }
        }