public void DrawString(SpriteBatch spriteBatch, string text, int x, int y, Color4 color) { if (text == "") //Skip empty strings { return; } var iter = new CodepointIterator(text); float penX = x, penY = y; while (iter.Iterate()) { uint c = iter.Codepoint; if (c == (uint)'\n') { penY += lineHeight; penX = x; continue; } var glyph = GetGlyph(c); if (glyph.Render) { spriteBatch.Draw( glyph.Texture, glyph.Rectangle, new Rectangle( (int)penX + glyph.XOffset, (int)penY + (LineHeight - glyph.YOffset), glyph.Rectangle.Width, glyph.Rectangle.Height ), color ); penX += glyph.HorizontalAdvance; penY += glyph.AdvanceY; } else { penX += glyph.AdvanceX; penY += glyph.AdvanceY; } if (glyph.Kerning && iter.Index < iter.Count - 1) { var g2 = GetGlyph(iter.PeekNext()); if (g2.Face == glyph.Face) { FT.FT_Vector vec; FT.FT_Get_Kerning(glyph.Face, glyph.CharIndex, g2.CharIndex, 2, out vec); var krn = FTMath.From26Dot6(vec.x); penX += krn; } } } }
public Point MeasureString(string text) { if (text == "") //Skip empty strings { return(new Point(0, 0)); } var iter = new CodepointIterator(text); float penX = 0, penY = 0; while (iter.Iterate()) { uint c = iter.Codepoint; if (c == (uint)'\n') { penY += lineHeight; penX = 0; continue; } var glyph = GetGlyph(c); if (glyph.Render) { penX += glyph.HorizontalAdvance; penY += glyph.AdvanceY; } else { penX += glyph.AdvanceX; penY += glyph.AdvanceY; } if (glyph.Kerning && iter.Index < iter.Count - 1) { var g2 = GetGlyph(iter.PeekNext()); if (g2.Face == glyph.Face) { FT.FT_Vector vec; FT.FT_Get_Kerning(glyph.Face, glyph.CharIndex, g2.CharIndex, 2, out vec); var krn = FTMath.From26Dot6(vec.x); penX += krn; } } } return(new Point((int)penX, (int)penY)); }