`setLineAlignment` set to Center/Right makes `getGlobalBounds` incorrect
Prerequisite Checklist
- I searched for existing issues to prevent duplicates
- I searched for existing discussions on the forum to prevent duplicates
- I am here to report an issue and not to just ask a question or look for help (use the forum or Discord instead)
Describe your issue here
getGlobalBounds for text does not seem to have the correct position when setLineAlignment is set anything but Left.
In the below image you can see the below shown code for each of the setLineAlignment values: top image is line alignment set to left, center is center and bottom image is right.
The size of getGlobalBounds remains the same, the position changes, which in the below example I am correcting for, so it still should be covering the whole render texture.
Line alignment set to center seems to move text by half a pixel and line alignment set to right seems to move text by a whole pixel, in which case part of it is drawn outside of the render texture.
I've tested this with a few fonts but below example is the impact font.
Your Environment
- SFML version: 3.1.0
Steps to reproduce
int main()
{
Font f("/usr/share/fonts/Impact-Font-Family/impact.ttf");
Text t(f);
t.setString("Test");
t.setLineAlignment(Text::LineAlignment::Left);
err() << t.getGlobalBounds().position.x << " " << t.getGlobalBounds().position.y << " " << t.getGlobalBounds().size.x << " " << t.getGlobalBounds().size.y << endl;
t.setPosition(-t.getGlobalBounds().position);
RenderTexture tex;
tex.resize(Vector2u(t.getGlobalBounds().size));
tex.clear();
tex.draw(t);
tex.display();
tex.getTexture().copyToImage().saveToFile("bug.png");
}Expected behavior
Global bounds are correct.
Actual behavior
Global bounds are not correct.
Source: SFML/SFML