migrate fonts to scoped resource ownership

- replace FontManager with per-ResourceScope FontService instances
  - publish font factories into explicit or default resource scopes
  - import default resources into UI scene scopes unless explicitly disabled
  - keep related font faces strongly owned without hot-path weak_ptr locking
  - add cached glyph advance queries without creating texture pages
  - fix font picker preview ownership, cleanup, and rapid switching
  - selectively evict TextLayout cache entries when referenced fonts unload
  - document FontService, ResourceCatalog, and cache invalidation semantics
  - migrate examples, tools, benchmarks, and tests to the scoped font API
  - expand coverage for font ownership, texture release, and layout caching
This commit is contained in:
Martín Lucas Golini
2026-07-24 01:54:51 -03:00
parent 24531b4411
commit 6b277e508b
83 changed files with 1940 additions and 828 deletions
+8 -7
View File
@@ -25,23 +25,24 @@ EE_MAIN_FUNC int main( int, char*[] ) {
"cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non "
"proident, sunt in culpa qui officia deserunt mollit anim id est laborum." );
FontTrueType* fontTest = FontTrueType::New( "DejaVuSansMono" );
FontTrueType* fontTest = FontTrueType::New( "DejaVuSansMono" ).get();
fontTest->loadFromFile( "assets/fonts/DejaVuSansMono.ttf" );
FontTrueType* fontTest2 = FontTrueType::New( "NotoSans-Regular" );
FontTrueType* fontTest2 = FontTrueType::New( "NotoSans-Regular" ).get();
fontTest2->loadFromFile( "assets/fonts/NotoSans-Regular.ttf" );
FontTrueType* fontEmoji = FontTrueType::New( "NotoEmoji-Regular" );
FontTrueType* fontEmoji = FontTrueType::New( "NotoEmoji-Regular" ).get();
fontEmoji->loadFromFile( "assets/fonts/NotoEmoji-Regular.ttf" );
FontTrueType* fontEmojiColor = FontTrueType::New( "NotoColorEmoji" );
FontTrueType* fontEmojiColor = FontTrueType::New( "NotoColorEmoji" ).get();
fontEmojiColor->loadFromFile( "assets/fonts/NotoColorEmoji.ttf" );
FontBMFont* fontBMFont = FontBMFont::New( "bmfont" );
FontBMFont* fontBMFont = FontBMFont::New( "bmfont" ).get();
fontBMFont->loadFromFile( "assets/fonts/bmfont.fnt" );
FontSprite* fontSprite = FontSprite::New(
"alagard" ); // Alagard - Hewett Tsoi ( https://www.dafont.com/alagard.font )
FontSprite* fontSprite =
FontSprite::New( "alagard" )
.get(); // Alagard - Hewett Tsoi ( https://www.dafont.com/alagard.font )
fontSprite->loadFromFile( "assets/fonts/custom_alagard.png", Color::Fuchsia, 32, -4 );
Text text;
+1 -1
View File
@@ -9,7 +9,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
FontTrueType* font =
FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" );
FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" ).get();
if ( !font || !font->loaded() )
return EXIT_FAILURE;
@@ -10,10 +10,15 @@ EE_MAIN_FUNC int main( int, char** ) {
return EXIT_FAILURE;
app.getUI()->setThreadPool( threadPool );
ResourceScope& resourceScope = *app.getUI()->getResourceScope();
FontTrueTypePtr remixIconFont =
FontTrueType::New( "icon", "assets/fonts/remixicon.ttf", resourceScope );
FontTrueTypePtr noniconsFont =
FontTrueType::New( "nonicons", "assets/fonts/nonicons.ttf", resourceScope );
FontTrueTypePtr codIconFont =
FontTrueType::New( "codicon", "assets/fonts/codicon.ttf", resourceScope );
app.getUI()->getUIIconThemeManager()->setCurrentTheme(
IconManager::init( "icons", FontTrueType::New( "icon", "assets/fonts/remixicon.ttf" ),
FontTrueType::New( "nonicons", "assets/fonts/nonicons.ttf" ),
FontTrueType::New( "codicon", "assets/fonts/codicon.ttf" ) ) );
IconManager::init( "icons", remixIconFont.get(), noniconsFont.get(), codIconFont.get() ) );
UIFontPickerDialog* dialog = UIFontPickerDialog::New();
dialog->setCloseShortcut( KEY_ESCAPE );
@@ -13,13 +13,12 @@ EE_MAIN_FUNC int main( int, char** ) {
// is always correct even if we load the application from other directory than the binary
// path.
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
// Load a font to use as the default font in our UI.
FontTrueType* font =
FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" );
// Create a new scene node to add our widgets.
UISceneNode* uiSceneNode = UISceneNode::New();
// Load a font to use as the default font in our UI.
FontTrueType* font = FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf",
*uiSceneNode->getResourceScope() )
.get();
// Set the default font used in the scene node (otherwise we won't have any font to create
// text views.
+8 -4
View File
@@ -63,11 +63,15 @@ EE_MAIN_FUNC int main( int argc, char** argv ) {
auto ui = app.getUI();
ui->setThreadPool( threadPool );
FontTrueType* remixIconFont = FontTrueType::New( "icon", "assets/fonts/remixicon.ttf" );
FontTrueType* noniconsFont = FontTrueType::New( "nonicons", "assets/fonts/nonicons.ttf" );
FontTrueType* codIconFont = FontTrueType::New( "codicon", "assets/fonts/codicon.ttf" );
ResourceScope& resourceScope = *ui->getResourceScope();
FontTrueTypePtr remixIconFont =
FontTrueType::New( "icon", "assets/fonts/remixicon.ttf", resourceScope );
FontTrueTypePtr noniconsFont =
FontTrueType::New( "nonicons", "assets/fonts/nonicons.ttf", resourceScope );
FontTrueTypePtr codIconFont =
FontTrueType::New( "codicon", "assets/fonts/codicon.ttf", resourceScope );
ui->getUIIconThemeManager()->setCurrentTheme(
IconManager::init( "icons", remixIconFont, noniconsFont, codIconFont ) );
IconManager::init( "icons", remixIconFont.get(), noniconsFont.get(), codIconFont.get() ) );
ui->setColorSchemePreference(
!prefersColorScheme.Get().empty()