From: Eunki Hong Date: Fri, 27 Dec 2024 05:30:58 +0000 (+0900) Subject: Return empty map and remove builder at Configuration getter if builder load failed X-Git-Tag: accepted/tizen/unified/x/20250402.101953~2^2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F28%2F317228%2F9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Return empty map and remove builder at Configuration getter if builder load failed It is possible that default theme builder load failed. Most of cases consider it, but StyleManager::GetConfiguration() didn't care that case. To ensure it, let we get LoadJSON result, and reset builder if load failed. And return empty Property::Map. ***************************************************************************************** NOTE 20250326: utc-Dali-StyleManager uses toolkit-text-abstraction. The segmentation fault seems to be caused by not finding the symbol. I added the missing APIs to the fake font client and checked that the problem is solved. + Excluded unrelated files from the commit. ***************************************************************************************** Change-Id: Icb40e69c19c48baa4c6b4350e6a495343e2cb47a Signed-off-by: Eunki Hong --- diff --git a/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp b/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp index 523c9c6f38..caa98f43e8 100644 --- a/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp +++ b/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Samsung Electronics Co., Ltd. + * Copyright (c) 2025 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1434,7 +1434,7 @@ int UtcDaliStyleManagerSetSubState02(void) END_TEST; } -int UtcDaliStyleManagerConfigSectionTest(void) +int UtcDaliStyleManagerConfigSectionTestP(void) { tet_infoline("Test that the properties in config section are works"); @@ -1483,6 +1483,51 @@ int UtcDaliStyleManagerConfigSectionTest(void) END_TEST; } +int UtcDaliStyleManagerConfigSectionTestN(void) +{ + tet_infoline("Test that the properties in config section are works as default if theme is broken"); + + const char* brokenTheme = "INVALID"; + + Test::StyleMonitor::SetThemeFileOutput(DALI_STYLE_DIR "dali-toolkit-default-theme.json", brokenTheme); + try + { + ToolkitTestApplication application; + + Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); + + Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); + DALI_TEST_CHECK(config.Empty()); + + // For coverage + Toolkit::TextEditor editor = Toolkit::TextEditor::New(); + editor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + application.GetScene().Add(editor); + + Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(editor); + + application.ProcessEvent(Integration::KeyEvent("", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", "", Device::Class::NONE, Device::Subclass::NONE)); + application.SendNotification(); + application.Render(); + + Toolkit::TextLabel label = Toolkit::TextLabel::New(); + label.SetProperty(Toolkit::TextLabel::Property::TEXT, "Hello, World!"); + application.GetScene().Add(label); + + application.SendNotification(); + application.Render(); + } + catch(...) + { + DALI_TEST_CHECK(false); ///< Should not get here + } + + // Restore default theme data. + Test::StyleMonitor::SetThemeFileOutput(DALI_STYLE_DIR "dali-toolkit-default-theme.json", defaultTheme); + + END_TEST; +} + int UtcDaliStyleManagerNewWithAdditionalBehavior(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-text-abstraction.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-text-abstraction.cpp index 84a46ea158..e8b3465708 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-text-abstraction.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-text-abstraction.cpp @@ -134,20 +134,35 @@ public: return fontClientHandle; } + void ClearCache() + { + } + void ClearCacheOnLocaleChanged() + { + } void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi) { } + void SetDpiFromWindowSystem() + { + } void GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi) { horizontalDpi = verticalDpi = 96; } - + int GetDefaultFontSize() + { + return 10.0f; + } void ResetSystemDefaults() { } void GetDefaultFonts(FontList& defaultFonts) { } + void InitDefaultFontDescription() + { + } void GetDefaultPlatformFontDescription(FontDescription& fontDescription) { } @@ -157,6 +172,10 @@ public: void GetDescription(FontId id, FontDescription& fontDescription) { } + bool IsCharacterSupportedByFont(FontId fontId, Character character) + { + return true; + } PointSize26Dot6 GetPointSize(FontId id) { return 9; @@ -191,6 +210,10 @@ public: void GetFixedSizes(const FontDescription& fontDescription, Dali::Vector& sizes) { } + bool HasItalicStyle(FontId fontId) const + { + return false; + } void GetFontMetrics(FontId fontId, FontMetrics& metrics) { } @@ -198,6 +221,10 @@ public: { return 0; } + GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector) + { + return 0; + } bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, bool horizontal) { return true; @@ -316,6 +343,13 @@ inline static TextAbstraction::Internal::FontClient& GetImplementation(TextAbstr return static_cast(handle); } +inline static const TextAbstraction::Internal::FontClient& GetImplementation(const TextAbstraction::FontClient& fontClient) +{ + DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty"); + const BaseObject& handle = fontClient.GetBaseObject(); + return static_cast(handle); +} + inline static TextAbstraction::Internal::Shaping& GetImplementation(TextAbstraction::Shaping& shaping) { DALI_ASSERT_ALWAYS(shaping && "shaping handle is empty"); @@ -420,16 +454,36 @@ FontClient& FontClient::operator=(const FontClient& handle) return *this; } +void FontClient::ClearCache() +{ + GetImplementation(*this).ClearCache(); +} + +void FontClient::ClearCacheOnLocaleChanged() +{ + GetImplementation(*this).ClearCacheOnLocaleChanged(); +} + void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi) { GetImplementation(*this).SetDpi(horizontalDpi, verticalDpi); } +void FontClient::SetDpiFromWindowSystem() +{ + GetImplementation(*this).SetDpiFromWindowSystem(); +} + void FontClient::GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi) { GetImplementation(*this).GetDpi(horizontalDpi, verticalDpi); } +int FontClient::GetDefaultFontSize() +{ + return GetImplementation(*this).GetDefaultFontSize(); +} + void FontClient::ResetSystemDefaults() { GetImplementation(*this).ResetSystemDefaults(); @@ -440,6 +494,11 @@ void FontClient::GetDefaultFonts(FontList& defaultFonts) GetImplementation(*this).GetDefaultFonts(defaultFonts); } +void FontClient::InitDefaultFontDescription() +{ + GetImplementation(*this).InitDefaultFontDescription(); +} + void FontClient::GetDefaultPlatformFontDescription(FontDescription& fontDescription) { GetImplementation(*this).GetDefaultPlatformFontDescription(fontDescription); @@ -460,6 +519,11 @@ PointSize26Dot6 FontClient::GetPointSize(FontId id) return GetImplementation(*this).GetPointSize(id); } +bool FontClient::IsCharacterSupportedByFont(FontId fontId, Character character) +{ + return GetImplementation(*this).IsCharacterSupportedByFont(fontId, character); +} + FontId FontClient::FindDefaultFont(Character charcode, PointSize26Dot6 pointSize, bool preferColor) { return GetImplementation(*this).FindDefaultFont(charcode, pointSize, preferColor); @@ -507,6 +571,11 @@ void FontClient::GetFixedSizes(const FontDescription& fontDescription, GetImplementation(*this).GetFixedSizes(fontDescription, sizes); } +bool FontClient::HasItalicStyle(FontId fontId) const +{ + return GetImplementation(*this).HasItalicStyle(fontId); +} + void FontClient::GetFontMetrics(FontId fontId, FontMetrics& metrics) { GetImplementation(*this).GetFontMetrics(fontId, metrics); @@ -517,6 +586,11 @@ GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode) return GetImplementation(*this).GetGlyphIndex(fontId, charcode); } +GlyphIndex FontClient::GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector) +{ + return GetImplementation(*this).GetGlyphIndex(fontId, charcode, variantSelector); +} + bool FontClient::GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal) { return GetImplementation(*this).GetGlyphMetrics(array, size, horizontal); diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index 8903bc1ecb..a0ce4a3b6a 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Samsung Electronics Co., Ltd. + * Copyright (c) 2025 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -175,7 +175,7 @@ void StyleManager::ApplyThemeStyle(Toolkit::Control control) ApplyDefaultTheme(); } - if(mThemeBuilder) + if(DALI_LIKELY(mThemeBuilder)) { ApplyStyle(mThemeBuilder, control); } @@ -295,12 +295,20 @@ const Property::Map& StyleManager::GetConfigurations() mThemeBuilder = CreateBuilder(mThemeBuilderConstants); // Load default theme because this is first try to load stylesheet. -#if defined(DEBUG_ENABLED) - bool themeLoaded = LoadJSON(mThemeBuilder, mDefaultThemeFilePath); + const bool themeLoaded = LoadJSON(mThemeBuilder, mDefaultThemeFilePath); DALI_LOG_STREAM(gLogFilter, Debug::Concise, " themeLoaded" << (themeLoaded ? "success" : "failure")); -#else - LoadJSON(mThemeBuilder, mDefaultThemeFilePath); -#endif + + if(DALI_UNLIKELY(!themeLoaded)) + { + DALI_LOG_STREAM(gLogFilter, Debug::Concise, "GetConfigurations() Failed\n"); + + // We tried to load a theme, but it failed. Ensure the builder is reset + mThemeBuilder.Reset(); + + static const Property::Map emptyMap; + + return emptyMap; + } mThemeFile = mDefaultThemeFilePath; }