diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index b6a5b0845..ec648227c 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -251,6 +251,7 @@ void Text::updateGeometry() float y = static_cast(m_characterSize); // Create one quad for each character + float minY = static_cast(m_characterSize); Uint32 prevChar = 0; for (std::size_t i = 0; i < m_string.getSize(); ++i) { @@ -275,10 +276,24 @@ void Text::updateGeometry() // Handle special characters switch (curChar) { - case L' ' : x += hspace; continue; - case L'\t' : x += hspace * 4; continue; - case L'\n' : y += vspace; x = 0; continue; - case L'\v' : y += vspace * 4; continue; + case L' ' : + x += hspace; + continue; + + case L'\t' : + x += hspace * 4; + continue; + + case L'\n' : + if (x > m_bounds.width) + m_bounds.width = x; + y += vspace; + x = 0; + continue; + + case L'\v' : + y += vspace * 4; + continue; } // Extract the current glyph's description @@ -302,6 +317,10 @@ void Text::updateGeometry() // Advance to the next character x += glyph.advance; + + // Update the minimum Y coordinate + if (y + top < minY) + minY = y + top; } // If we're using the underlined style, add the last line @@ -316,8 +335,12 @@ void Text::updateGeometry() m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1))); } - // Recompute the bounding rectangle - m_bounds = m_vertices.getBounds(); + // Update the bounding rectangle + m_bounds.left = 0; + m_bounds.top = minY; + if (x > m_bounds.width) + m_bounds.width = x; + m_bounds.height = y - minY; } } // namespace sf