diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index e487e073..45f6baf8 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -61,6 +61,21 @@ namespace void close(FT_Stream) { } + + // Helper to intepret memory as a specific type + template + inline T reinterpret(const U& input) + { + T output; + std::memcpy(&output, &input, sizeof(U)); + return output; + } + + // Combine outline thickness, boldness and codepoint into a single 64-bit key + sf::Uint64 combine(float outlineThickness, bool bold, sf::Uint32 codePoint) + { + return (static_cast(reinterpret(outlineThickness)) << 32) | (static_cast(bold) << 31) | codePoint; + } } @@ -332,9 +347,7 @@ const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool b GlyphTable& glyphs = m_pages[characterSize].glyphs; // Build the key by combining the code point, bold flag, and outline thickness - Uint64 key = (static_cast(*reinterpret_cast(&outlineThickness)) << 32) - | (static_cast(bold ? 1 : 0) << 31) - | static_cast(codePoint); + Uint64 key = combine(outlineThickness, bold, codePoint); // Search the glyph into the cache GlyphTable::const_iterator it = glyphs.find(key);