| 59 | } |
| 60 | |
| 61 | sf::Vector2f Engine::GetFontHeightProperties( const sf::Font& font, unsigned int font_size ) const { |
| 62 | // We want to cache line height values because they are expensive to compute. |
| 63 | |
| 64 | static std::map<std::pair<void*, unsigned int>, sf::Vector2f> height_property_cache; |
| 65 | |
| 66 | // Get the font face that Laurent tries to hide from us. |
| 67 | struct FontStruct { |
| 68 | void* library; |
| 69 | void* font_face; // Authentic SFML comment: implementation details |
| 70 | void* unused1; |
| 71 | void* unused2; |
| 72 | int* unused3; |
| 73 | std::string family; |
| 74 | |
| 75 | // Since maps allocate everything non-contiguously on the heap we can use void* instead of Page here. |
| 76 | mutable std::map<unsigned int, void*> unused4; |
| 77 | mutable std::vector<std::uint8_t> unused5; |
| 78 | }; |
| 79 | |
| 80 | // All your font face are belong to us too. |
| 81 | void* face = reinterpret_cast<const FontStruct&>( font ).font_face; |
| 82 | |
| 83 | std::pair<void*, unsigned int> id( face, font_size ); |
| 84 | |
| 85 | std::map<std::pair<void*, unsigned int>, sf::Vector2f>::iterator iter( height_property_cache.find( id ) ); |
| 86 | |
| 87 | if( iter != height_property_cache.end() ) { |
| 88 | return iter->second; |
| 89 | } |
| 90 | |
| 91 | sf::Vector2f properties( 0.f, 0.f ); |
| 92 | |
| 93 | if( m_character_sets.empty() ) { |
| 94 | for( std::uint32_t current_character = 0; current_character < 0x0370; ++current_character ) { |
| 95 | const auto& glyph = font.getGlyph( current_character, font_size, false ); |
| 96 | properties.x = std::max( properties.x, static_cast<float>( glyph.bounds.size.y ) ); |
| 97 | properties.y = std::max( properties.y, static_cast<float>( -glyph.bounds.position.y ) ); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | for( const auto character_set : m_character_sets ) { |
| 102 | for( std::uint32_t current_character = character_set.first; current_character < character_set.second; ++current_character ) { |
| 103 | const auto& glyph = font.getGlyph( current_character, font_size, false ); |
| 104 | properties.x = std::max( properties.x, static_cast<float>( glyph.bounds.size.y ) ); |
| 105 | properties.y = std::max( properties.y, static_cast<float>( -glyph.bounds.position.y ) ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | height_property_cache[id] = properties; |
| 110 | |
| 111 | return properties; |
| 112 | } |
| 113 | |
| 114 | float Engine::GetFontLineHeight( const sf::Font& font, unsigned int font_size ) const { |
| 115 | return GetFontHeightProperties( font, font_size ).x; |