Clear font cache when locale changed 22/303122/20
authorANZ1217 <chihun.jeong@samsung.com>
Wed, 20 Dec 2023 06:23:18 +0000 (15:23 +0900)
committerANZ1217 <chihun.jeong@samsung.com>
Thu, 28 Dec 2023 04:39:46 +0000 (13:39 +0900)
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

automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp
automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor-impl.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.h
dali-toolkit/internal/text/controller/text-controller-impl.h
dali-toolkit/internal/text/controller/text-controller.cpp
dali-toolkit/internal/text/controller/text-controller.h
dali-toolkit/internal/text/multi-language-support-impl.cpp
dali-toolkit/internal/text/multi-language-support-impl.h

index 297525a..a81a462 100755 (executable)
@@ -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
index 4f15239..31de850 100644 (file)
@@ -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
index 126a67a..a705241 100644 (file)
@@ -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;
 };
 
index 6d3c511..b9e94ed 100644 (file)
@@ -66,6 +66,11 @@ public:
     return mMainWindow;
   }
 
+  Dali::Adaptor& GetAdaptor()
+  {
+    return *mAdaptor;
+  }
+
 private:
   Dali::Window mMainWindow;
   std::unique_ptr< Adaptor > mAdaptor;
index aeb2a5e..a455a54 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/object/property-helper-devel.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/object/type-registry-helper.h>
@@ -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())
 {
 }
 
index 66cb0a6..7ef28c6 100644 (file)
@@ -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;
index c6d8b8c..1024869 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
 #include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/input-style.h>
+#include <dali-toolkit/internal/text/multi-language-support.h>
 #include <dali-toolkit/internal/text/text-model.h>
 #include <dali-toolkit/internal/text/text-view.h>
 #include <dali-toolkit/public-api/styling/style-manager.h>
@@ -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();
index 8f7a99e..469c273 100644 (file)
@@ -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;
index 7612b2d..fcd6166 100644 (file)
@@ -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.
    */
index b322683..41ba5ac 100644 (file)
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/common/singleton-service.h>
 #include <dali/devel-api/text-abstraction/font-client.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/trace.h>
 
@@ -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;
index a9b8f4e..2f0a904 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/base-object.h>
+#include <dali/public-api/signals/connection-tracker.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/multi-language-support.h>
@@ -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<FontRun>&                        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<DefaultFonts*>           mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
   Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
 
+  std::string mLocale;
+
   //Methods
 
   /**