From 84e0a25e04dda9f56cabd0b39da52551ea3b98bb Mon Sep 17 00:00:00 2001 From: Radek Dutkiewicz Date: Wed, 20 Jan 2021 19:36:24 +0000 Subject: [PATCH] Fixed unnecessary loadGlyph() calls getKerning() now passes the bold flag to getGlyph() function, so already cached glyph can be used. --- include/SFML/Graphics/Font.hpp | 2 +- src/SFML/Graphics/Font.cpp | 6 +++--- src/SFML/Graphics/Text.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index 14446339a..f5e1d9b69 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -217,7 +217,7 @@ public: /// \return Kerning value for \a first and \a second, in pixels /// //////////////////////////////////////////////////////////// - float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const; + float getKerning(Uint32 first, Uint32 second, unsigned int characterSize, bool bold = false) const; //////////////////////////////////////////////////////////// /// \brief Get the line spacing diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 9e104035c..b5284b6a2 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -376,7 +376,7 @@ bool Font::hasGlyph(Uint32 codePoint) const //////////////////////////////////////////////////////////// -float Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const +float Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize, bool bold) const { // Special case where first or second is 0 (null character) if (first == 0 || second == 0) @@ -391,8 +391,8 @@ float Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) FT_UInt index2 = FT_Get_Char_Index(face, second); // Retrieve position compensation deltas generated by FT_LOAD_FORCE_AUTOHINT flag - float firstRsbDelta = getGlyph(first, characterSize, false).rsb_delta; - float secondLsbDelta = getGlyph(second, characterSize, false).lsb_delta; + float firstRsbDelta = getGlyph(first, characterSize, bold).rsb_delta; + float secondLsbDelta = getGlyph(second, characterSize, bold).lsb_delta; // Get the kerning vector FT_Vector kerning; diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 11d52010b..eb2600c72 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -332,7 +332,7 @@ Vector2f Text::findCharacterPos(std::size_t index) const Uint32 curChar = m_string[i]; // Apply the kerning offset - position.x += m_font->getKerning(prevChar, curChar, m_characterSize); + position.x += m_font->getKerning(prevChar, curChar, m_characterSize, isBold); prevChar = curChar; // Handle special characters @@ -451,7 +451,7 @@ void Text::ensureGeometryUpdate() const continue; // Apply the kerning offset - x += m_font->getKerning(prevChar, curChar, m_characterSize); + x += m_font->getKerning(prevChar, curChar, m_characterSize, isBold); // If we're using the underlined style and there's a new line, draw a line if (isUnderlined && (curChar == L'\n' && prevChar != L'\n'))