Non-Alpha Numeric Characters padding String Size in Runtime Fonts

I’m getting the length of a string like this:

int32 StringSizeX;
int32 StringSizeY;
UCanvas::ClippedStrLen(Cast<const UFont>(FontToUse), 1.f, 1.f, StringSizeX, StringSizeY, *TextToDraw.ToString());

I then offset the draw position for my string so it’s right aligned and draw it to the screen.

I’m using a run-time font object as I want to support non-English characters so I’m not sure if this problem exists with offline fonts.

This isn’t specific to the font I’m using as this behavior occurs with Roboto and several others I have on hand.

Any small non-alpha-numeric characters like !,.’ etc cause the calculated string length to be longer than it is when it’s actually drawn to screen.

You can see the issue below. All I’ve changed is the text being drawn.

46238-kerningproblem.jpg

The very odd part is that the string size with these special characters is even larger than when they are replaced with X (the largest character).

Just converted the larger font to an offline font and there are no errors in the reported size vs the displayed size. This is definitely a problem relating to runtime fonts.

I should specify that there are still some errors with the offline font but they are not as egregious. Offline fonts with Legacy mode enabled in the import options are exactly the right size.

Hi SquidInABox,

I just ran a test in 4.7.6 and was able to see results very similar to what you showed.

47910-stringlength.png

However, when I converted the project to 4.8.1 and ran it again, the individual strings appeared to be right-aligned much better, if not perfectly.

47921-stringlength1.png

If you have a to test your project in 4.8.1, do you see the same improvement?