SFML community forums

Help => Graphics => Topic started by: mkalex777 on May 29, 2016, 04:25:32 pm

Title: CSFML 2.3 render text GetLocalBounds bug
Post by: mkalex777 on May 29, 2016, 04:25:32 pm
I'm using UbuntuMono-R.ttf
MD5: 9383F4B0BC1D264A5A7E094EB1ED0C0B
Link: http://db.onlinewebfonts.com/t/9383f4b0bc1d264a5a7e094eb1ed0c0b.ttf

It's monospace font, and it works fine with different strings - all letters with the same size.

But now I found two strings, for which Text::GetLocalBounds returns incorrect sizes.
It happens with Text::CharacterSize = 20.

Example:

string "Level:" => size = [59; 26] (bounds = [FloatRect] Left=2; Top=6; Width=55; Height=14)
string "Xp:   " => size = [60; 30] (bounds = [FloatRect] Left=0; Top=7; Width=60; Height=16)

I'm calculate text size from bounds with the following code:
        public static Vector2f MeasureText(this Text text)
        {
            var bounds = text.GetLocalBounds();
            var size = new Vector2f(bounds.Width, bounds.Height);
            var padding = new Vector2f(bounds.Left, bounds.Top);
            return size + padding * 2F;
        }
 

For both strings GetLocalBounds should return the same size.

Is it really CSFML 2.3 bug? Or may be it's just incorrect way to calculate the text size?
How to fix it in order to get the same size for both strings. Because the font is monospace.