From bcb013b45b89528608809bdd68b6a86cd0949b8c Mon Sep 17 00:00:00 2001 From: assematt Date: Fri, 16 Dec 2016 10:52:19 -0500 Subject: [PATCH] Fixed bug in sf::Text when applying an outline color/thickness 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. --- src/SFML/Graphics/Text.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 3773616d3..fae7d9ac0 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -444,12 +444,15 @@ void Text::ensureGeometryUpdate() const { Uint32 curChar = m_string[i]; + // Skip the \r char to avoid weird graphical issues + if (curChar == '\r') + continue; + // Apply the kerning offset x += m_font->getKerning(prevChar, curChar, m_characterSize); - prevChar = curChar; // If we're using the underlined style and there's a new line, draw a line - if (isUnderlined && (curChar == L'\n')) + if (isUnderlined && (curChar == L'\n' && prevChar != L'\n')) { addLine(m_vertices, x, y, m_fillColor, underlineOffset, underlineThickness); @@ -458,7 +461,7 @@ void Text::ensureGeometryUpdate() const } // If we're using the strike through style and there's a new line, draw a line across all characters - if (isStrikeThrough && (curChar == L'\n')) + if (isStrikeThrough && (curChar == L'\n' && prevChar != L'\n')) { addLine(m_vertices, x, y, m_fillColor, strikeThroughOffset, underlineThickness); @@ -466,6 +469,8 @@ void Text::ensureGeometryUpdate() const addLine(m_outlineVertices, x, y, m_outlineColor, strikeThroughOffset, underlineThickness, m_outlineThickness); } + prevChar = curChar; + // Handle special characters if ((curChar == L' ') || (curChar == L'\n') || (curChar == L'\t')) {