How to tell how wide a string is?


#1

In a paint method, when using something like Graphics::drawFittedText() or any other text method available, is there a way to find out the width and height needed for a string? Or the width that the text method just used?

I’d like to draw some images following displaying some text, but I cannot figure out how to determine the width of the displayed string on the Graphics context.

[size=75](Searching on the forum did bring up a super funny thread from a disgruntled user last year about hinting, small font sizes, and low-res screens, but nothing that answered my question. Julian: thumbs up to you for locking that thread and leaving it there!)[/size]


#2

There is Font::getStringWidth() for single-line text, or you could use a GlyphArrangement yourself, which has a getBoundingBox() function.


#3

That looks perfect, thanks!