From 2db12350e78821ecb6fa15ffd92c2835d380c779 Mon Sep 17 00:00:00 2001 From: Radek Dutkiewicz Date: Tue, 19 Jul 2022 01:19:25 +0100 Subject: [PATCH] Fix corelation between text setOutlineThickness() and getLocalBounds() This fixes text crawling explained in issue #2129 --- src/SFML/Graphics/Text.cpp | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index fe61bd650..e06b4b646 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -500,19 +500,8 @@ void Text::ensureGeometryUpdate() const { const Glyph& glyph = m_font->getGlyph(curChar, m_characterSize, isBold, m_outlineThickness); - float left = glyph.bounds.left; - float top = glyph.bounds.top; - float right = glyph.bounds.left + glyph.bounds.width; - float bottom = glyph.bounds.top + glyph.bounds.height; - // Add the outline glyph to the vertices addGlyphQuad(m_outlineVertices, Vector2f(x, y), m_outlineColor, glyph, italicShear); - - // Update the current bounds with the outlined glyph bounds - minX = std::min(minX, x + left - italicShear * bottom); - maxX = std::max(maxX, x + right - italicShear * top); - minY = std::min(minY, y + top); - maxY = std::max(maxY, y + bottom); } // Extract the current glyph's description @@ -521,24 +510,31 @@ void Text::ensureGeometryUpdate() const // Add the glyph to the vertices addGlyphQuad(m_vertices, Vector2f(x, y), m_fillColor, glyph, italicShear); - // Update the current bounds with the non outlined glyph bounds - if (m_outlineThickness == 0) - { - float left = glyph.bounds.left; - float top = glyph.bounds.top; - float right = glyph.bounds.left + glyph.bounds.width; - float bottom = glyph.bounds.top + glyph.bounds.height; + // Update the current bounds + float left = glyph.bounds.left; + float top = glyph.bounds.top; + float right = glyph.bounds.left + glyph.bounds.width; + float bottom = glyph.bounds.top + glyph.bounds.height; - minX = std::min(minX, x + left - italicShear * bottom); - maxX = std::max(maxX, x + right - italicShear * top); - minY = std::min(minY, y + top); - maxY = std::max(maxY, y + bottom); - } + minX = std::min(minX, x + left - italicShear * bottom); + maxX = std::max(maxX, x + right - italicShear * top); + minY = std::min(minY, y + top); + maxY = std::max(maxY, y + bottom); // Advance to the next character x += glyph.advance + letterSpacing; } + // If we're using outline, update the current bounds + if (m_outlineThickness != 0) + { + float outline = std::abs(std::ceil(m_outlineThickness)); + minX -= outline; + maxX += outline; + minY -= outline; + maxY += outline; + } + // If we're using the underlined style, add the last line if (isUnderlined && (x > 0)) {