public static CachedString Create(IFont font, string s) { if (string.IsNullOrWhiteSpace(s)) { return(_cachedString ??= new CachedString(new CachedChar[0], Vector2.Zero, font.FontSheet)); } float maxX = 0; float maxY = 0; float currentX = 0; var chars = new CachedChar[s.Length]; for (int i = 0; i < s.Length; i++) { chars[i] = new CachedChar(new Vector2(currentX, maxY), font.GetPosition(s[i])); var symbolOffset = font.GetOffset(s[i]); if (symbolOffset.Y > float.Epsilon) { maxX = Math.Max(currentX, maxX); maxY += symbolOffset.Y; currentX = 0; } else { currentX += symbolOffset.X; maxX = Math.Max(currentX, maxX); } } return(new CachedString(chars, new Vector2(maxX, maxY + font.SymbolMaxSize.Y), font.FontSheet)); }
public void DrawString(IFont font, SpriteBatch sb, string str, Vector2 position, Color color) { float xOffset = 0; float yOffset = 0; for (int i = 0; i < str.Length; i++) { sb.Draw(font.FontSheet, position + (Vector2.UnitX * xOffset) + (Vector2.UnitY * yOffset), font.GetPosition(str[i]), color); var symbolOffset = font.GetOffset(str[i]); if (symbolOffset.Y > float.Epsilon) { yOffset += symbolOffset.Y; xOffset = 0; } else { xOffset += symbolOffset.X; } } }