mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-28 17:16:29 +03:00
Fix a possible crash when loading fonts.
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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(
|
||||
<vbox layout_width="match_parent" layout_height="match_parent">
|
||||
<TextView id="tiny" text="Tiny text" font_size="1" />
|
||||
<TextView id="small" text="Small text" font_size="3" />
|
||||
<TextView id="normal" text="Normal text" font_size="14" />
|
||||
</vbox>
|
||||
)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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user