From d676584a4cb6eef8410fd1d7f23fc838ac398f99 Mon Sep 17 00:00:00 2001 From: ANZ1217 Date: Fri, 22 Dec 2023 14:38:29 +0900 Subject: [PATCH] Add LocaleChangedSignal LocaleChangedSignal is a signal that works when the system locale is changed. To solve the problem that the default font does not change when changing the system language, clear the cache of fontClient and emit LocaleChangedSignal. Change-Id: Ic543b9fc250ccf88cd460fe08da6b5fd2c008987 --- dali/devel-api/text-abstraction/font-client.cpp | 5 +++ dali/devel-api/text-abstraction/font-client.h | 7 ++++ dali/integration-api/adaptor-framework/adaptor.h | 8 +++++ dali/internal/adaptor/common/adaptor-impl.h | 10 ++++++ dali/internal/adaptor/common/adaptor.cpp | 5 +++ .../adaptor/tizen-wayland/adaptor-impl-tizen.cpp | 8 +++++ .../text/text-abstraction/font-client-impl.cpp | 8 +++++ .../text/text-abstraction/font-client-impl.h | 5 +++ .../plugin/font-client-plugin-cache-handler.cpp | 41 ++++++++++++++++++++++ .../plugin/font-client-plugin-cache-handler.h | 5 +++ .../plugin/font-client-plugin-impl.cpp | 5 +++ .../plugin/font-client-plugin-impl.h | 5 +++ 12 files changed, 112 insertions(+) diff --git a/dali/devel-api/text-abstraction/font-client.cpp b/dali/devel-api/text-abstraction/font-client.cpp index 116c00a..10e23d3 100644 --- a/dali/devel-api/text-abstraction/font-client.cpp +++ b/dali/devel-api/text-abstraction/font-client.cpp @@ -112,6 +112,11 @@ 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); diff --git a/dali/devel-api/text-abstraction/font-client.h b/dali/devel-api/text-abstraction/font-client.h index bce3e4e..61647ec 100644 --- a/dali/devel-api/text-abstraction/font-client.h +++ b/dali/devel-api/text-abstraction/font-client.h @@ -164,6 +164,13 @@ public: void ClearCache(); /** + * @brief Clear caches in FontClient when Locale Changed + * + * @note This function only clears caches that needs to be cleared. + */ + void ClearCacheOnLocaleChanged(); + + /** * @brief Set the DPI of the target window. * * @note Multiple windows are not currently supported. diff --git a/dali/integration-api/adaptor-framework/adaptor.h b/dali/integration-api/adaptor-framework/adaptor.h index 0d80b35..07e78a6 100644 --- a/dali/integration-api/adaptor-framework/adaptor.h +++ b/dali/integration-api/adaptor-framework/adaptor.h @@ -119,6 +119,7 @@ class DALI_ADAPTOR_API Adaptor public: typedef Signal AdaptorSignalType; ///< Generic Type for adaptor signals typedef Signal WindowCreatedSignalType; ///< SceneHolder created signal type + typedef Signal LocaleChangedSignalType; ///< Locale changed signal type using SurfaceSize = Uint16Pair; ///< Surface size type @@ -486,6 +487,13 @@ public: // Signals */ WindowCreatedSignalType& WindowCreatedSignal(); + /** + * @brief This signal is emitted when the system locale is changed + * + * @return The signal to connect to + */ + LocaleChangedSignalType& LocaleChangedSignal(); + private: // Undefined Adaptor(const Adaptor&); diff --git a/dali/internal/adaptor/common/adaptor-impl.h b/dali/internal/adaptor/common/adaptor-impl.h index 20b93a8..aaff350 100644 --- a/dali/internal/adaptor/common/adaptor-impl.h +++ b/dali/internal/adaptor/common/adaptor-impl.h @@ -96,6 +96,7 @@ class Adaptor : public Integration::RenderController, public: using AdaptorSignalType = Dali::Adaptor::AdaptorSignalType; using WindowCreatedSignalType = Dali::Adaptor::WindowCreatedSignalType; + using LocaleChangedSignalType = Dali::Adaptor::LocaleChangedSignalType; using SurfaceSize = Uint16Pair; ///< Surface size type @@ -566,6 +567,14 @@ public: // Signals return mWindowCreatedSignal; } + /** + * @copydoc Dali::Adaptor::LocaleChangedSignal + */ + LocaleChangedSignalType& LocaleChangedSignal() + { + return mLocaleChangedSignal; + } + public: // From Dali::Internal::Adaptor::CoreEventInterface /** * @copydoc Dali::Internal::Adaptor::CoreEventInterface:::FlushUpdateMessages() @@ -703,6 +712,7 @@ private: // Data AdaptorSignalType mResizedSignal; ///< Resized signal. AdaptorSignalType mLanguageChangedSignal; ///< Language changed signal. WindowCreatedSignalType mWindowCreatedSignal; ///< Window created signal. + LocaleChangedSignalType mLocaleChangedSignal; ///< Locale changed signal. Dali::Adaptor& mAdaptor; ///< Reference to public adaptor instance. State mState; ///< Current state of the adaptor diff --git a/dali/internal/adaptor/common/adaptor.cpp b/dali/internal/adaptor/common/adaptor.cpp index c8d17ee..9c347b4 100644 --- a/dali/internal/adaptor/common/adaptor.cpp +++ b/dali/internal/adaptor/common/adaptor.cpp @@ -135,6 +135,11 @@ Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal() return mImpl->WindowCreatedSignal(); } +Adaptor::LocaleChangedSignalType& Adaptor::LocaleChangedSignal() +{ + return mImpl->LocaleChangedSignal(); +} + Dali::RenderSurfaceInterface& Adaptor::GetSurface() { return mImpl->GetSurface(); diff --git a/dali/internal/adaptor/tizen-wayland/adaptor-impl-tizen.cpp b/dali/internal/adaptor/tizen-wayland/adaptor-impl-tizen.cpp index 3442ca1..1e415a9 100644 --- a/dali/internal/adaptor/tizen-wayland/adaptor-impl-tizen.cpp +++ b/dali/internal/adaptor/tizen-wayland/adaptor-impl-tizen.cpp @@ -35,6 +35,9 @@ #include #include +// INTERNAL INCLUDES +#include + namespace Dali { namespace Internal @@ -56,7 +59,12 @@ static void OnSystemLanguageChanged(system_settings_key_e key, void* data) Adaptor* adaptor = static_cast(data); if(adaptor != NULL) { + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.ClearCacheOnLocaleChanged(); + fontClient.InitDefaultFontDescription(); + adaptor->SetRootLayoutDirection(locale); + adaptor->LocaleChangedSignal().Emit(locale); } free(locale); diff --git a/dali/internal/text/text-abstraction/font-client-impl.cpp b/dali/internal/text/text-abstraction/font-client-impl.cpp index 3b960a7..031c78a 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-impl.cpp @@ -335,6 +335,14 @@ void FontClient::ClearCache() } } +void FontClient::ClearCacheOnLocaleChanged() +{ + if(mPlugin) + { + mPlugin->ClearCacheOnLocaleChanged(); + } +} + void FontClient::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi) { mDpiHorizontal = horizontalDpi; diff --git a/dali/internal/text/text-abstraction/font-client-impl.h b/dali/internal/text/text-abstraction/font-client-impl.h index ca7fe5e..ff86fd9 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.h +++ b/dali/internal/text/text-abstraction/font-client-impl.h @@ -98,6 +98,11 @@ public: // API for Dali::TextAbstraction::FontClient used. void ClearCache(); /** + * @copydoc Dali::TextAbstraction::FontClient::ClearCacheOnLocaleChanged() + */ + void ClearCacheOnLocaleChanged(); + + /** * @copydoc Dali::TextAbstraction::FontClient::SetDpi() */ void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi); diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.cpp b/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.cpp index 2509c8d..d1d24a1 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.cpp @@ -358,6 +358,47 @@ void FontClient::Plugin::CacheHandler::ClearCache() mDefaultFontDescriptionCached = false; } +void FontClient::Plugin::CacheHandler::ClearCacheOnLocaleChanged() +{ + // delete cached glyph informations before clear mFontFaceCache. + mGlyphCacheManager->ClearCache(); + + mDefaultFontDescription = FontDescription(); + + mSystemFonts.clear(); + mDefaultFonts.clear(); + + DestroyCharacterSets(mDefaultFontCharacterSets); + mDefaultFontCharacterSets.Clear(); + + ClearFallbackCache(); + mFallbackCache.clear(); + + mFontIdCache.clear(); + + ClearCharacterSetFromFontFaceCache(); + mFontFaceCache.clear(); + + mValidatedFontCache.clear(); + mFontDescriptionCache.clear(); + + DestroyCharacterSets(mCharacterSetCache); + mCharacterSetCache.Clear(); + + mFontDescriptionSizeCache.clear(); + mFontDescriptionSizeCache.rehash(0); // Note : unordered_map.clear() didn't deallocate memory + + mEllipsisCache.clear(); + mPixelBufferCache.clear(); + mEmbeddedItemCache.clear(); + mBitmapFontCache.clear(); + + mLatestFoundFontDescription.family.clear(); + mLatestFoundCacheKey = FontDescriptionSizeCacheKey(0, 0); + + mDefaultFontDescriptionCached = false; +} + void FontClient::Plugin::CacheHandler::ResetSystemDefaults() { mDefaultFontDescriptionCached = false; diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.h b/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.h index d61fb72..5f4f0fd 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.h +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.h @@ -132,6 +132,11 @@ public: // Clear cache public void ClearCache(); /** + * @copydoc Dali::TextAbstraction::FontClient::Plugin::ClearCacheOnLocaleChanged() + */ + void ClearCacheOnLocaleChanged(); + + /** * @copydoc Dali::TextAbstraction::FontClient::Plugin::ResetSystemDefaults() */ void ResetSystemDefaults(); diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp index d31df24..99caffe 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp @@ -269,6 +269,11 @@ void FontClient::Plugin::ClearCache() const mCacheHandler->ClearCache(); } +void FontClient::Plugin::ClearCacheOnLocaleChanged() const +{ + mCacheHandler->ClearCacheOnLocaleChanged(); +} + void FontClient::Plugin::SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi) { diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h index 172b247..ef47387 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h @@ -95,6 +95,11 @@ public: // Dali::TextAbstraction::FontClient void ClearCache() const; /** + * @copydoc Dali::TextAbstraction::FontClient::ClearCacheOnLocaleChanged() + */ + void ClearCacheOnLocaleChanged() const; + + /** * @copydoc Dali::TextAbstraction::FontClient::SetDpi() */ void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi); -- 2.7.4