public string GetWrappedText(string text)
{
if(WordWrap <= 0) return text;
text = Regex.Replace(text, @"\r\n", "\n");
string[] lines = Regex.Split(text, @"\n");
float cursorX = 0f;
for(int i = 0; i < lines.Length; i++)
{
List<string> words = new List<string>(lines[i].Split(' '));
cursorX = 0;
for(int j = 0; j < words.Count; j++)
{
string word = words[j];
if (Alignment == TTextAlignment.Right)
word = " " + word;
else
word += " ";
float wordWidth = GetStringWidth(word);
cursorX += wordWidth;
if(cursorX > WordWrap)
{
// Wrap this word to the next line
cursorX = wordWidth;
if(j > 0)
words[j - 1] += "\n";
}
else if(j > 0)
{
words[j - 1] += " ";
}
}
lines[i] = System.String.Join(System.String.Empty, words.ToArray());
}
return System.String.Join("\n", lines);
}