Fix: UISceneNode::reevaluateFontStyle() now preserves an existing FontTrueType family when it already owns the requested bold, italic, or bold-italic variant.

This commit is contained in:
Martín Lucas Golini
2026-08-23 18:53:45 -03:00
parent 65a389aa96
commit 6b27ea2dc8
2 changed files with 29 additions and 0 deletions

View File

@@ -2418,6 +2418,15 @@ Font* UISceneNode::reevaluateFontStyle( Font* currentFont, Uint32 fontStyle,
return nullptr;
auto authorFamilyIt = mFontFaceFamilies.find( currentFont );
auto* currentTrueTypeFont = static_cast<FontTrueType*>( currentFont );
if ( authorFamilyIt == mFontFaceFamilies.end() ) {
const Uint32 weightStyle = fontStyle & ( Text::Bold | Text::Italic );
if ( ( weightStyle == Text::Bold && currentTrueTypeFont->getBoldFont() ) ||
( weightStyle == Text::Italic && currentTrueTypeFont->getItalicFont() ) ||
( weightStyle == ( Text::Bold | Text::Italic ) &&
currentTrueTypeFont->getBoldItalicFont() ) )
return nullptr;
}
if ( authorFamilyIt == mFontFaceFamilies.end() && !SystemFontResolver::isEnabled() )
return nullptr;

View File

@@ -274,6 +274,26 @@ UTEST( FontRendering, loadingFontFamilyDoesNotCreateTexturePages ) {
EXPECT_EQ( textureCount, textureFactory->getTextureCount() );
}
UTEST( FontRendering, systemResolverPreservesRelatedBoldFont ) {
UIApplication app(
WindowSettings( 320, 240, "eepp - Preserve Related Bold Font", WindowStyle::Default,
WindowBackend::Default, 32 ),
UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) );
ResourceScope& scope = *app.getUI()->getResourceScope();
FontTrueTypePtr font = FontTrueType::New( "BundledNotoSans-Regular", scope );
ASSERT_TRUE(
font->loadFromFile( Sys::getProcessPath() + "../assets/fonts/NotoSans-Regular.ttf" ) );
FontFamily::loadFromRegular( font.get() );
ASSERT_TRUE( font->getBoldFont() );
FontTrueType* bundledBold = font->getBoldFont().get();
SystemFontResolver::setEnabled( true );
EXPECT_EQ( nullptr,
app.getUI()->reevaluateFontStyle( font.get(), Text::Bold, FontWeight::Bold ) );
EXPECT_EQ( bundledBold, font->getGlyph( 'A', 16, true, false ).font );
SystemFontResolver::setEnabled( false );
}
UTEST( FontRendering, regularFontOwnsRelatedFonts ) {
FontTrueTypePtr font = FontTrueType::New( "RelatedFonts-Regular" );
FontTrueTypePtr bold = FontTrueType::New( "RelatedFonts-Bold" );