public int GetWidth(ref string text) { int w = 0; if (text != null) { AtlasChar prev = null; AtlasChar chr; for (int i = 0; i < text.Length; ++i) { chr = GetChar(text[i]); if (prev != null) { w += prev.GetKerning(text[i]); } w += chr.Advance; prev = chr; } //For the final character, we want to slice off the character spacing if (prev != null) { w -= prev.Advance - prev.Image.Width; } } return(w); }
public void DrawText(AtlasFont font, ref string text, Vector2 position, Color4 color) { var pos = position; AtlasChar prev = null; AtlasChar chr; for (int i = 0; i < text.Length; ++i) { chr = font.GetChar(text[i]); if (prev != null) { pos.X += prev.GetKerning(chr.Char); } if (chr.Image != null) { DrawImage(chr.Image, pos, color); } pos.X += chr.Advance; prev = chr; } }