Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: bug in sf::Text when applying an outline color/thickness  (Read 2274 times)

0 Members and 1 Guest are viewing this topic.

assematt

  • Newbie
  • *
  • Posts: 3
    • View Profile
bug in sf::Text when applying an outline color/thickness
« on: December 16, 2016, 05:37:45 pm »
When applying an outline thickness to sf::Text in combination with a strikethrough and/or an underlined style, the ensureGeometryUpdate function adds unwanted vertices if the string contains two consecutive '\n' charecter. To fix this we need to add an additional check in the if statements to check if both the current and previous character it's a new line character.

This is a visual representation of the bug


And this is the code that generated it.

sf::Text TestString;
TestString.setFont(TestFont);
TestString.setCharacterSize(60u);
TestString.setOutlineColor(sf::Color::Red);
TestString.setOutlineThickness(2.f);
TestString.setStyle(sf::Text::StrikeThrough | sf::Text::Underlined);
TestString.setString("Line 1\n\nLine 2");

This is the portion of code that generated the bug.
(click to show/hide)

And this is the fixed one
(click to show/hide)
« Last Edit: December 16, 2016, 06:00:57 pm by assematt »

assematt

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: bug in sf::Text when applying an outline color/thickness
« Reply #1 on: December 16, 2016, 08:29:07 pm »
Also as eXpl0it3r pointed out in the pull request on github that SFML only correctly support '\n' as a new line character in the ensureGeometryUpdate() function, if we have '\r\n' as a new line character that the ensureGeometryUpdate() function adds an extra blank character in the vertex array. So I updated the code to support also \r\n as new line character. That said isn't it better to just convert the new line characters when calling setString() from \r\n to \n?

This is a visual representation of the bug when using \r\n.
« Last Edit: December 16, 2016, 08:32:26 pm by assematt »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: bug in sf::Text when applying an outline color/thickness
« Reply #2 on: December 17, 2016, 10:18:07 am »
I actually think "\r" shouldn't be ignored and instead be processed as expected (i.e. reset x position for next glyph).

The common use case in Windows line breaks won't be affected, but it would also make it possible to actually utilize it the way it's meant to be (return to the start of the line without beginning a new line).

assematt

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: bug in sf::Text when applying an outline color/thickness
« Reply #3 on: December 21, 2016, 07:18:12 pm »
I updated the code to better support \r\n as new line char without a graphic glitch.
Now sf::Text should not produce unwanted graphics glitches when using an outline color/thickness if the sf::Text string contains two consecutive new line character.

Here some screen for comparison, the text on the left is produced by the old code, the on on the right is produced by the new code

sf::Text TestString;
TestString.setFont(TestFont);
TestString.setCharacterSize(60u);
TestString.setOutlineColor(sf::Color::Red);
TestString.setOutlineThickness(2.f);
TestString.setStyle(sf::Text::StrikeThrough | sf::Text::Underlined);
TestString.setString("Line 1\r\nLine 2");




sf::Text TestString;
TestString.setFont(TestFont);
TestString.setCharacterSize(60u);
TestString.setOutlineColor(sf::Color::Red);
TestString.setOutlineThickness(2.f);
TestString.setStyle(sf::Text::StrikeThrough | sf::Text::Underlined);
TestString.setString("Line 1\r\n\r\nLine 2");

 

anything