Hi,
I’m trying to calculate the size of a string for fitting purposes (using font size etc…), but it seems that advance property doesnt really matches rect sizedelta. (worldspace canvas, no scale applied).
There’s a small % of difference…
public static int GetWordLength(this string word, Font font, int fontSize, FontStyle fontStyle)
{
int charLength = 0;
CharacterInfo ci;
for (int i = 0; i < word.Length; i++)
{
bool ok = font.GetCharacterInfo(word[i], out ci, fontSize, fontStyle);
if (ok)
charLength += ci.advance;
else
Debug.LogError("Char not found: '" + word[i] + "'");
}
return charLength;
}
basically what I want to do is rendering a text inside an ellipse. I thought I could split entire text into words and knowing the rect width of each word I could have used spaces at start/end of each the line to follow ellipse curves (or any other shape).
I also thought about creating Text components for each line and then populate each line separately, but the problem is always the same: knowing how much space will texts take inside rect.
Do you think there’s a better approach?Is it possible with TextMeshPro? @Stephan_B
thx