static void WriteGlyphs(StaticSpriteFontData spriteFont, Glyph[] glyphs) { spriteFont.Glyphs = new Graphics.Font.Glyph[glyphs.Length]; for (int i = 0; i < glyphs.Length; i++) { var glyph = glyphs[i]; spriteFont.Glyphs[i] = new Graphics.Font.Glyph { Character = glyph.Character, Subrect = new Core.Mathematics.Rectangle(glyph.Subrect.X, glyph.Subrect.Y, glyph.Subrect.Width, glyph.Subrect.Height), Offset = new Vector2(glyph.XOffset, glyph.YOffset), XAdvance = glyph.XAdvance, }; } }
public StaticSpriteFont(FontSystem fontSystem, StaticSpriteFontData spriteFontData) : base(fontSystem, spriteFontData, false) { characterToGlyph = new Dictionary <char, Glyph>(spriteFontData.Glyphs.Length); // build the character map foreach (var glyph in spriteFontData.Glyphs) { var character = (char)glyph.Character; characterToGlyph[character] = glyph; } // Prepare kernings if they are available. var kernings = spriteFontData.Kernings; if (kernings != null) { for (int i = 0; i < kernings.Length; i++) { int key = (kernings[i].First << 16) | kernings[i].Second; KerningMap.Add(key, kernings[i].Offset); } } // Read the texture data. StaticTextures = new Texture2D[spriteFontData.Bitmaps.Length]; for (int i = 0; i < StaticTextures.Length; i++) { if (spriteFontData.Bitmaps[i].Value != null) { StaticTextures[i] = Texture2D.New(fontSystem.GraphicsDevice, spriteFontData.Bitmaps[i].Value).DisposeBy(this); } } Textures = StaticTextures; BaseOffsetY = spriteFontData.BaseOffset; DefaultLineSpacing = spriteFontData.FontDefaultLineSpacing; }
public static StaticSpriteFontData CreateSpriteFontData(SpriteFontAsset options, Glyph[] glyphs, float lineSpacing, float baseLine, Bitmap bitmap) { var spriteFontData = new StaticSpriteFontData { Size = FontHelper.PointsToPixels(options.Size), BaseOffset = baseLine, FontDefaultLineSpacing = lineSpacing, ExtraLineSpacing = options.LineSpacing, ExtraSpacing = options.Spacing, DefaultCharacter = options.DefaultCharacter }; WriteGlyphs(spriteFontData, glyphs); spriteFontData.Bitmaps = new ContentReference <Graphics.Image> [1]; var image = GetImage(options, bitmap); spriteFontData.Bitmaps[0] = new ContentReference <Graphics.Image> { Value = image }; return(spriteFontData); }
public SpriteFont NewStatic(StaticSpriteFontData data) { return(new StaticSpriteFont(this, data)); }