From dc0dfd601ad33dbabeea427903417daef061c1d3 Mon Sep 17 00:00:00 2001 From: Mario Liebisch Date: Sun, 29 Jul 2018 09:25:48 +0200 Subject: [PATCH] Squash duplicated sf::Font glyphs to single chars Before this change, `sf::Font` always rendered/provided one character per Unicode codepoint, even if that character wasn't represented by the current font file or duplicated. This caused more texture space to be used than necessary, which is especially apparent, when trying to render a large amount of unhandled glyphs (the texture would literally fill up with empty squares representing missing characters). --- src/SFML/Graphics/Font.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 45f6baf87..b6f5c604c 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -71,10 +71,10 @@ namespace return output; } - // Combine outline thickness, boldness and codepoint into a single 64-bit key - sf::Uint64 combine(float outlineThickness, bool bold, sf::Uint32 codePoint) + // Combine outline thickness, boldness and font glyph index into a single 64-bit key + sf::Uint64 combine(float outlineThickness, bool bold, sf::Uint32 index) { - return (static_cast(reinterpret(outlineThickness)) << 32) | (static_cast(bold) << 31) | codePoint; + return (static_cast(reinterpret(outlineThickness)) << 32) | (static_cast(bold) << 31) | index; } } @@ -346,8 +346,8 @@ const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool b // Get the page corresponding to the character size GlyphTable& glyphs = m_pages[characterSize].glyphs; - // Build the key by combining the code point, bold flag, and outline thickness - Uint64 key = combine(outlineThickness, bold, codePoint); + // Build the key by combining the glyph index (based on code point), bold flag, and outline thickness + Uint64 key = combine(outlineThickness, bold, FT_Get_Char_Index(static_cast(m_face), codePoint)); // Search the glyph into the cache GlyphTable::const_iterator it = glyphs.find(key);