New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sf::Text bounds are incorrect in case of underline and strikethrough #2711
Comments
@eXpl0it3r @ChrisThrasher Take a look at this above and at the repo with example program and fix, and decide if this is a problem that should be fixed. Maybe binary1248 can comment if he is available since he worked on this? The fix I tried in the repo isn't a good one since it changes bounds even in normal cases, and it needlessly looks at all vertices again, but it's a starting point to consider what 'nicer' bounds can look like. |
What would a unit test look like to catch this? Maybe we check the local bounds of "Test" then add an underline and observe that the local bounds do not change? Would that be a valid test for this bug? |
There was once a discussion on the forum about text bounds: https://en.sfml-dev.org/forums/index.php?topic=24985.0 It was me, exploiter and Laurent. It was only about trailing and leading spaces in text making the bounds bigger - I disagreed with that approach (but looking at it today after working with positioning texts next to each other - I think it's correct after all). In last post there is a weak comment by exploiter implying that he thought that underline and strikethrough should change bounds: "take the underline or strike-through decorations, should the bounding box not be adjusted for the now visible space character or visible decorations?" |
The existing EDIT: I opened #2712 to give us a better foundation for testing changes to |
Subject of the issue
Local (and thus global) bounds of SFML text do not take underline and strikethrough into account.
Your environment
Steps to reproduce
Make an sf::Text instance with style underline set on it, get bounds, try display that bounding box using sf::RectangleShape or similar, see that underline is outside the rectangle drawn.
A more through example with interactive changing of styles, text and outline size, and my (bad - I don't recommend it) attempt at a fix is available at https://github.com/FRex/sfml-text-bounds-with-underline
Expected behavior
Underline should be included in the bounding box, so it should fall inside the drawn rectangle shape. Use case I have is having a background box drawn under sf::Text using these bounds. There is no way to know how big the box should be now, due to missing underline.
Actual behavior
Underline falls outside the drawn shape, because the bounds don't take underline (and strikethrough) into account. They do take bold and italic styles, and outline thickness (including negative) into account. Also scree screenshot below (result of above program) and repo linked above for more examples.
The text was updated successfully, but these errors were encountered: