float GetStringWidth(string str)
{
TGlyph prevGlyph = null;
bool inControlCode = false;
float width = 0f;
foreach (char c in str)
{
int charCode = (int)c;
if (inControlCode)
{
inControlCode = false;
if (charCode >= 48 && charCode <= 57) // 0-9
{
continue;
}
}
else
{
if (charCode == 92) // Backslash
{
inControlCode = true;
continue;
}
}
TGlyph glyph = Font.Glyphs.Get(charCode);
if (glyph == null)
continue;
float kerning = 0f;
if (prevGlyph != null)
kerning = prevGlyph.GetKerning(charCode) * Size;
width += glyph.xAdvance * Size + Tracking + kerning;
prevGlyph = glyph;
}
return width;
}