| 106 | } |
| 107 | |
| 108 | Primitive::Ptr Renderer::CreateText( const sf::Text& text ) { |
| 109 | const auto& font = text.getFont(); |
| 110 | auto character_size = text.getCharacterSize(); |
| 111 | auto color = text.getFillColor(); |
| 112 | |
| 113 | auto atlas_offset = LoadFont( font, character_size ); |
| 114 | |
| 115 | const auto& str = text.getString(); |
| 116 | |
| 117 | auto horizontal_spacing = static_cast<float>( font.getGlyph( L' ', character_size, false ).advance ); |
| 118 | auto vertical_spacing = static_cast<float>( Context::Get().GetEngine().GetFontLineHeight( font, character_size ) ); |
| 119 | sf::Vector2f start_position( std::floor( text.getPosition().x + .5f ), std::floor( text.getPosition().y + static_cast<float>( character_size ) + .5f ) ); |
| 120 | |
| 121 | sf::Vector2f position( start_position ); |
| 122 | |
| 123 | const static auto tab_spaces = 2.f; |
| 124 | |
| 125 | std::uint32_t previous_character = 0; |
| 126 | |
| 127 | auto primitive = std::make_shared<Primitive>( str.getSize() * 4 ); |
| 128 | |
| 129 | Primitive character_primitive( 4 ); |
| 130 | |
| 131 | for( const auto& current_character : str ) { |
| 132 | position.x += static_cast<float>( font.getKerning( previous_character, current_character, character_size ) ); |
| 133 | |
| 134 | switch( current_character ) { |
| 135 | case L' ': |
| 136 | position.x += horizontal_spacing; |
| 137 | continue; |
| 138 | case L'\t': |
| 139 | position.x += horizontal_spacing * tab_spaces; |
| 140 | continue; |
| 141 | case L'\n': |
| 142 | position.y += vertical_spacing; |
| 143 | position.x = start_position.x; |
| 144 | continue; |
| 145 | case L'\v': |
| 146 | position.y += vertical_spacing * tab_spaces; |
| 147 | continue; |
| 148 | default: |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | const auto& glyph = font.getGlyph( current_character, character_size, false ); |
| 153 | |
| 154 | PrimitiveVertex vertex0; |
| 155 | PrimitiveVertex vertex1; |
| 156 | PrimitiveVertex vertex2; |
| 157 | PrimitiveVertex vertex3; |
| 158 | |
| 159 | vertex0.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.position.x ), static_cast<float>( glyph.bounds.position.y ) ); |
| 160 | vertex1.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.position.x ), static_cast<float>( glyph.bounds.position.y + glyph.bounds.size.y ) ); |
| 161 | vertex2.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.position.x + glyph.bounds.size.x ), static_cast<float>( glyph.bounds.position.y ) ); |
| 162 | vertex3.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.position.x + glyph.bounds.size.x ), static_cast<float>( glyph.bounds.position.y + glyph.bounds.size.y ) ); |
| 163 | |
| 164 | vertex0.color = color; |
| 165 | vertex1.color = color; |
no test coverage detected