AHUD::GetTextsize(), returns bad width

Hi there,

I’m trying to justify my DrawTexts to the right using GetTextSize(). It appears to return a width larger than the actual text render width :

34726-clipboard-1.jpg

The yellow DebugLines under the text show the width returned by GetTextSize() for each line of text. As you can see, the text render is not as wide.

It looks like the higher the number of chars in the string, the bigger the error on the width. Not sure though…
I use a runtime font.

Any thoughts ?
Thanks in advance.

Please guys,

TextSize systematically returns a width higher than the actual display width.
Is there anybody in there ?

With certain Fonts, GetTextSize() will return a wrong width, causing many text display issues, bad centering etc… Even the flashing cursor is misplaced in the command-line.
This is such a basic feature. I wonder why this has not been investigated yet.

For me it always returns 0 (with default font).
Have you found any fix or workaround yet?

No, I did not investigate that any further. Ultimately, I’ll end up changing the font, as the errors seem to vary widely from one font to the other. But such a decision would deeply impact the design in the whole game. That would be a pain at this stage.

Thanks for your reply. Have you ever tried it with the default font? For me using 4.8.3 that doesn’t work at all :frowning:

I’m sorry for necroing a very old post, but I came across this as I was working through a similar problem and I think I found the cause and the solution.

The cause: when using DrawText you might be using Kerning that doesn’t match the Font->Kerning, then when you call GetTextSize() it’s not matching because it pulls the Kerning from the font.
The solution: Preface… I have no idea if this works for all fonts, just worked for the limited ones that I tested. Some pseudo code. GetTextSize(…); text_width += text.Num() * Font->Kerning; for me I was able to set the kerning when I set up my font and then in my DrawText calls. I used the Font->Kerning for the Kerning parameter of the DrawText calls.