diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index a116a5f53..c8ed8d345 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -1461,7 +1461,7 @@ Glyph FontTrueType::loadGlyphByIndex( Uint32 index, unsigned int characterSize, page.texture->update( pixelPtr, w, h, x, y ); - if ( scale < 1.f ) + if ( scale < 1.f && pixelPtr != mPixelBuffer.data() ) eeSAFE_DELETE_ARRAY( pixelPtr ); } diff --git a/src/eepp/graphics/image.cpp b/src/eepp/graphics/image.cpp index 28cb5f02e..06a268ee1 100644 --- a/src/eepp/graphics/image.cpp +++ b/src/eepp/graphics/image.cpp @@ -1321,7 +1321,8 @@ void Image::copyImage( Graphics::Image* image, const Uint32& x, const Uint32& y void Image::resize( const Uint32& newWidth, const Uint32& newHeight, ResamplerFilter filter ) { if ( newWidth == 0 || newHeight == 0 ) { - Log::warning( "Image::resize: Invalid resize %dx%d", newWidth, newHeight ) ; + Log::warning( "Image::resize: Invalid resize %dx%d (from %dx%d)", newWidth, newHeight, + mWidth, mHeight ); return; } diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index 4302cb83d..9157d0d14 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -227,11 +227,17 @@ void StyleSheetProperty::checkVars() { static void varToVal( VariableFunctionCache& varCache, const std::string& varDef ) { FunctionString functionType = FunctionString::parse( varDef ); if ( !functionType.getParameters().empty() ) { + bool foundVar = false; for ( auto& val : functionType.getParameters() ) { if ( String::startsWith( val, "--" ) ) { varCache.variableList.emplace_back( val ); + foundVar = true; } else if ( String::startsWith( val, "var(" ) ) { varToVal( varCache, val ); + foundVar = true; + } else if ( foundVar ) { + // This is a fallback value (comes after the variable name) + varCache.variableList.emplace_back( val ); } } } diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index ebcb5de16..c389a2c42 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -122,6 +122,8 @@ Uint32 UITextView::getFontSize() const { UITextView* UITextView::setFontSize( const Uint32& characterSize ) { if ( mTextCache.getCharacterSize() != characterSize ) { + if ( characterSize == 0 ) + return this; mFontStyleConfig.CharacterSize = characterSize; mTextCache.setFontSize( characterSize ); recalculate(); diff --git a/src/tests/unit_tests/uihtml_tests.cpp b/src/tests/unit_tests/uihtml_tests.cpp index 41b966f61..b66d5c89b 100644 --- a/src/tests/unit_tests/uihtml_tests.cpp +++ b/src/tests/unit_tests/uihtml_tests.cpp @@ -2357,3 +2357,51 @@ UTEST( UIHTML, blockFlowFloat ) { } Engine::destroySingleton(); } + +UTEST( FontTrueType, glyphScaleZeroDimensionsNoCrash ) { + Engine::instance()->createWindow( WindowSettings( 1024, 650, "Glyph Scale Test", + WindowStyle::Default, WindowBackend::Default, + 32, {}, 1, false, true ), + ContextSettings( false, 0, 0, GLv_default, true, false ) ); + FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + + FontTrueType* font = FontTrueType::New( "NotoSans-Regular" ); + font->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" ); + ASSERT_TRUE( font != nullptr && font->loaded() ); + FontFamily::loadFromRegular( font ); + + for ( unsigned int size : { 1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u } ) { + for ( Uint32 ch : { 'A', 'Z', 'a', 'z', '0', '9', '!', '@', '#', '$' } ) { + const Glyph& glyph = font->getGlyph( ch, size, false, false, 0.f ); + (void)glyph; + } + } + + UI::UISceneNode* sceneNode = UI::UISceneNode::New(); + SceneManager::instance()->add( sceneNode ); + UI::UIThemeManager* themeManager = sceneNode->getUIThemeManager(); + themeManager->setDefaultFont( font ); + + sceneNode->loadLayoutFromString( R"html( + + + + + + )html" ); + + sceneNode->updateDirtyLayouts(); + + auto tiny = sceneNode->getRoot()->find( "tiny" ); + auto small = sceneNode->getRoot()->find( "small" ); + auto normal = sceneNode->getRoot()->find( "normal" ); + + ASSERT_TRUE( tiny != nullptr ); + ASSERT_TRUE( small != nullptr ); + ASSERT_TRUE( normal != nullptr ); + + EXPECT_GT( normal->getPixelsSize().getWidth(), 0 ); + EXPECT_GT( normal->getPixelsSize().getHeight(), 0 ); + + Engine::destroySingleton(); +}