CharacterInfo advance and rect size

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…

What’s the correct numeric relationship?

thx

:frowning:

Is this related to TextMesh Pro?

I’m using a simple dynamic font and I just need to know the length of single words inside a recttransform cause I’m doing wordwrap manually.

below you can see what I do:

    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;
    }

it can’t be that difficult to know how much horizontal space inside Rect any text would take…:eyes: I wonder how unity word wrapping is working…

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