diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index f7cc296c0..329f307aa 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -2418,6 +2418,15 @@ Font* UISceneNode::reevaluateFontStyle( Font* currentFont, Uint32 fontStyle, return nullptr; auto authorFamilyIt = mFontFaceFamilies.find( currentFont ); + auto* currentTrueTypeFont = static_cast( 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; diff --git a/src/tests/unit_tests/fontrendering_tests.cpp b/src/tests/unit_tests/fontrendering_tests.cpp index 5db5008ad..e4d4e8424 100644 --- a/src/tests/unit_tests/fontrendering_tests.cpp +++ b/src/tests/unit_tests/fontrendering_tests.cpp @@ -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" );