Ejemplo n.º 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]);
            }
        }
Ejemplo n.º 2
0
 private void Initialize(GraphicsDevice graphicsDevice, IFont font, float height, Vector2 spacing, bool useNative)
 {
     this.graphicsDevice = graphicsDevice;
     this.font           = font;
     this.height         = height;
     this.spacing        = spacing;
     this.useNative      = useNative;
     Glyphs = new Dictionary <char, Glyph>();
     Glyph[] Glyph = font.GetGlyphsFromCodepoint(height, new int[] { 'A', '国' }, 1f, 1f);
     defaultGlyph   = Glyph[0];
     defaultGlyphCn = Glyph[1];
 }