MCPcopy Create free account
hub / github.com/TankOs/SFGUI / LoadFont

Method LoadFont

src/SFGUI/Renderer.cpp:530–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528/// @cond
529
530sf::Vector2f Renderer::LoadFont( const sf::Font& font, unsigned int size ) {
531 // Get the font face that Laurent tries to hide from us.
532 struct FontStruct {
533 void* library;
534 void* font_face; // Authentic SFML comment: implementation details
535 void* unused1;
536 void* unused2;
537 int* unused3;
538 std::string family;
539
540 // Since maps allocate everything non-contiguously on the heap we can use void* instead of Page here.
541 mutable std::map<unsigned int, void*> unused4;
542 mutable std::vector<std::uint8_t> unused5;
543 };
544
545 // All your font face are belong to us too.
546 void* face = reinterpret_cast<const FontStruct&>( font ).font_face;
547
548 FontID id( face, size );
549
550 std::map<FontID, PrimitiveTexture::Ptr >::iterator iter( m_fonts.find( id ) );
551
552 if( iter != m_fonts.end() ) {
553 return iter->second->offset;
554 }
555
556 // If the user does not specify their own character sets, make sure all the glyphs we need are loaded.
557 if( m_character_sets.empty() ) {
558 for( std::uint32_t codepoint = 0; codepoint < 0x0370; ++codepoint ) {
559 (void)font.getGlyph( codepoint, size, false );
560 }
561 }
562
563 // Make a local copy to avoid unnecessary dereferencing.
564 for( const auto character_set : m_character_sets ) {
565 for( auto codepoint = character_set.first; codepoint < character_set.second; ++codepoint ) {
566 (void)font.getGlyph( codepoint, size, false );
567 }
568 }
569
570 const auto image = font.getTexture( size ).copyToImage();
571
572 const auto handle = LoadTexture( image );
573
574 m_fonts[id] = handle;
575
576 return handle->offset;
577}
578
579PrimitiveTexture::Ptr Renderer::LoadTexture( const sf::Texture& texture ) {
580 return LoadTexture( texture.copyToImage() );

Callers 1

GetFontMethod · 0.45

Calls 2

endMethod · 0.80
emptyMethod · 0.80

Tested by

no test coverage detected