From: ANZ1217 Date: Wed, 20 Dec 2023 06:23:18 +0000 (+0900) Subject: [Tizen] Clear font cache when locale changed X-Git-Tag: accepted/tizen/8.0/unified/20240109.155453~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F303621%2F1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Clear font cache when locale changed Fix the problem that the font does not change because the font cache of the multi-language-support and text-controller does not disappear when the language is changed. Change-Id: Ib6afee3101d87cd09a1a0c9af5c9f33b16bf84cb --- diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp index 297525a..a81a462 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp @@ -1950,4 +1950,23 @@ int UtcDaliTextMultiLanguageDefaultFontsCache(void) DALI_TEST_EQUALS(DEFAULT_FONTS_REMAIN_COUNT, defaultFontsPerScript->mFonts.size(), TEST_LOCATION); END_TEST; +} + +int UtcDaliTextMultiLanguageLocaleChange(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextMultiLanguageLocaleChange"); + + Adaptor &adaptor = application.GetAdaptor(); + MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get(); + + std::string newLocale = "multi_TEST"; + adaptor.LocaleChangedSignal().Emit(newLocale); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(newLocale.data(), GetImplementation(multilanguageSupport).GetLocale(), TEST_LOCATION); + + END_TEST; } \ No newline at end of file diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp index 4f15239..31de850 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp @@ -1338,3 +1338,26 @@ int UtcDaliTextLabelMarkupSpanCharacterSpacing(void) END_TEST; } + +int UtcDaliTextLabelLocaleChange(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextLabelLocaleChange "); + + Adaptor &adaptor = application.GetAdaptor(); + TextLabel textLabel = TextLabel::New(); + application.GetScene().Add(textLabel); + + application.SendNotification(); + application.Render(); + + std::string newLocale = "label_TEST"; + adaptor.LocaleChangedSignal().Emit(newLocale); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(newLocale.data(), GetImpl(textLabel).GetLocale(), TEST_LOCATION); + + END_TEST; +} \ No newline at end of file diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor-impl.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor-impl.h index 126a67a..a705241 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor-impl.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor-impl.h @@ -92,6 +92,7 @@ public: Dali::Adaptor::AdaptorSignalType& ResizedSignal(); Dali::Adaptor::AdaptorSignalType& LanguageChangedSignal(); Dali::Adaptor::WindowCreatedSignalType& WindowCreatedSignal(); + Dali::Adaptor::LocaleChangedSignalType& LocaleChangedSignal(); static Adaptor& GetImpl( Dali::Adaptor& adaptor ) { return *adaptor.mImpl; } static const Adaptor& GetImpl( const Dali::Adaptor& adaptor ) { return *adaptor.mImpl; } @@ -104,6 +105,7 @@ private: Dali::Adaptor::AdaptorSignalType mResizedSignal; Dali::Adaptor::AdaptorSignalType mLanguageChangedSignal; Dali::Adaptor::WindowCreatedSignalType mWindowCreatedSignal; + Dali::Adaptor::LocaleChangedSignalType mLocaleChangedSignal; TestApplication* mTestApplication; }; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.h index 6d3c511..b9e94ed 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.h @@ -66,6 +66,11 @@ public: return mMainWindow; } + Dali::Adaptor& GetAdaptor() + { + return *mAdaptor; + } + private: Dali::Window mMainWindow; std::unique_ptr< Adaptor > mAdaptor; diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index aeb2a5e..a455a54 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -943,6 +944,11 @@ void TextLabel::OnInitialize() self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged); + if(Dali::Adaptor::IsAvailable()) + { + Dali::Adaptor::Get().LocaleChangedSignal().Connect(this, &TextLabel::OnLocaleChanged); + } + Layout::Engine& engine = mController->GetLayoutEngine(); engine.SetCursorWidth(0u); // Do not layout space for the cursor. @@ -1267,6 +1273,20 @@ void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type mController->ChangedLayoutDirection(); } +void TextLabel::OnLocaleChanged(std::string locale) +{ + if(mLocale != locale) + { + mLocale = locale; + mController->ResetFontAndStyleData(); + } +} + +std::string TextLabel::GetLocale() +{ + return mLocale; +} + void TextLabel::EmitTextFitChangedSignal() { Dali::Toolkit::TextLabel handle(GetOwner()); @@ -1282,7 +1302,8 @@ TextLabel::TextLabel(ControlBehaviour additionalBehaviour) : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)), mRenderingBackend(DEFAULT_RENDERING_BACKEND), mTextUpdateNeeded(false), - mLastAutoScrollEnabled(false) + mLastAutoScrollEnabled(false), + mLocale(std::string()) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index 66cb0a6..7ef28c6 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -193,6 +193,11 @@ public: */ bool IsTextFitArrayEnabled() const; + /** + * @brief Gets the locale. + */ + std::string GetLocale(); + private: // From Control /** * @copydoc Control::OnInitialize() @@ -307,6 +312,12 @@ private: void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type); /** + * @brief Callback function for when the locale is changed. + * @param[in] locale The new system locale. + */ + void OnLocaleChanged(std::string locale); + + /** * @brief Emits TextFitChanged signal. */ void EmitTextFitChangedSignal(); @@ -324,6 +335,8 @@ private: // Data Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal; Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal; + std::string mLocale; + int mRenderingBackend; bool mTextUpdateNeeded : 1; bool mLastAutoScrollEnabled : 1; diff --git a/dali-toolkit/internal/text/controller/text-controller-impl.h b/dali-toolkit/internal/text/controller/text-controller-impl.h index c6d8b8c..1024869 100644 --- a/dali-toolkit/internal/text/controller/text-controller-impl.h +++ b/dali-toolkit/internal/text/controller/text-controller-impl.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -440,6 +441,16 @@ struct Controller::Impl } /** + * @copydoc Text::Controller::ResetFontAndStyleData() + */ + void ResetFontAndStyleData() + { + ClearFontData(); + ClearStyleData(); + RequestRelayout(); + } + + /** * @brief Helper to move the cursor, grab handle etc. */ bool ProcessInputEvents(); diff --git a/dali-toolkit/internal/text/controller/text-controller.cpp b/dali-toolkit/internal/text/controller/text-controller.cpp index 8f7a99e..469c273 100644 --- a/dali-toolkit/internal/text/controller/text-controller.cpp +++ b/dali-toolkit/internal/text/controller/text-controller.cpp @@ -308,6 +308,11 @@ void Controller::ChangedLayoutDirection() mImpl->mIsLayoutDirectionChanged = true; } +void Controller::ResetFontAndStyleData() +{ + mImpl->ResetFontAndStyleData(); +} + void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type) { mImpl->mModel->mMatchLayoutDirection = type; diff --git a/dali-toolkit/internal/text/controller/text-controller.h b/dali-toolkit/internal/text/controller/text-controller.h index 7612b2d..fcd6166 100644 --- a/dali-toolkit/internal/text/controller/text-controller.h +++ b/dali-toolkit/internal/text/controller/text-controller.h @@ -1875,6 +1875,11 @@ public: // Queries & retrieves. void ChangedLayoutDirection(); /** + * @brief Clear font and style data. + */ + void ResetFontAndStyleData(); + + /** * @brief Retrieves if showing real text or not. * @return The value of showing real text. */ diff --git a/dali-toolkit/internal/text/multi-language-support-impl.cpp b/dali-toolkit/internal/text/multi-language-support-impl.cpp index b322683..41ba5ac 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.cpp +++ b/dali-toolkit/internal/text/multi-language-support-impl.cpp @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include #include #include @@ -256,7 +257,8 @@ void DefaultFonts::Cache(const TextAbstraction::FontDescription& description, Fo MultilanguageSupport::MultilanguageSupport() : mDefaultFontPerScriptCache(), - mValidFontsPerScriptCache() + mValidFontsPerScriptCache(), + mLocale(std::string()) { // Initializes the default font cache to zero (invalid font). // Reserves space to cache the default fonts and access them with the script as an index. @@ -265,6 +267,11 @@ MultilanguageSupport::MultilanguageSupport() // Initializes the valid fonts cache to NULL (no valid fonts). // Reserves space to cache the valid fonts and access them with the script as an index. mValidFontsPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL); + + if(Dali::Adaptor::IsAvailable()) + { + Dali::Adaptor::Get().LocaleChangedSignal().Connect(this, &MultilanguageSupport::OnLocaleChanged); + } } MultilanguageSupport::~MultilanguageSupport() @@ -288,6 +295,29 @@ MultilanguageSupport::~MultilanguageSupport() } } +void MultilanguageSupport::OnLocaleChanged(std::string locale) +{ + if(mLocale != locale) + { + mLocale = locale; + ClearCache(); + } +} + +void MultilanguageSupport::ClearCache() +{ + mDefaultFontPerScriptCache.Clear(); + mValidFontsPerScriptCache.Clear(); + + mDefaultFontPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL); + mValidFontsPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL); +} + +std::string MultilanguageSupport::GetLocale() +{ + return mLocale; +} + Text::MultilanguageSupport MultilanguageSupport::Get() { Text::MultilanguageSupport multilanguageSupportHandle; diff --git a/dali-toolkit/internal/text/multi-language-support-impl.h b/dali-toolkit/internal/text/multi-language-support-impl.h index a9b8f4e..2f0a904 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.h +++ b/dali-toolkit/internal/text/multi-language-support-impl.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -132,7 +133,7 @@ struct DefaultFonts /** * @brief Multi-language support implementation. @see Text::MultilanguageSupport. */ -class MultilanguageSupport : public BaseObject +class MultilanguageSupport : public BaseObject, public ConnectionTracker { public: /** @@ -173,10 +174,28 @@ public: Length numberOfCharacters, Vector& fonts); + /** + * @brief Callback function for when the locale is changed. + * @param[in] locale The new system locale. + */ + void OnLocaleChanged(std::string locale); + + /** + * @brief Clear font caches when locale changed. + */ + void ClearCache(); + + /** + * @brief Gets the locale. + */ + std::string GetLocale(); + private: Vector mDefaultFontPerScriptCache; ///< Caches default fonts for a script. Vector mValidFontsPerScriptCache; ///< Caches valid fonts for a script. + std::string mLocale; + //Methods /**