[4.0] clear cache when locale is changed 39/170039/5
authorminho.sun <minho.sun@samsung.com>
Mon, 12 Feb 2018 11:35:33 +0000 (20:35 +0900)
committerminho.sun <minho.sun@samsung.com>
Wed, 14 Feb 2018 06:16:15 +0000 (15:16 +0900)
When locale is change, font configuration might provide a different font
list.

In this case, original cached font might not be valid for same script.
Therefore, we need to clear caches.

Change-Id: I76b2f195be323a87b9076c8b11575f306336225a
Signed-off-by: minho.sun <minho.sun@samsung.com>
dali-toolkit/internal/text/multi-language-support-impl.cpp
dali-toolkit/internal/text/multi-language-support-impl.h

index 723a343..df31e56 100644 (file)
@@ -40,6 +40,7 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_MULT
 #endif
 
 const Dali::Toolkit::Text::Character UTF32_A = 0x0041;
+
 }
 
 namespace Text
@@ -98,7 +99,8 @@ void DefaultFonts::Cache( const TextAbstraction::FontDescription& description, F
 
 MultilanguageSupport::MultilanguageSupport()
 : mDefaultFontPerScriptCache(),
-  mValidFontsPerScriptCache()
+  mValidFontsPerScriptCache(),
+  mSlotDelegate( this )
 {
   // 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.
@@ -121,6 +123,22 @@ MultilanguageSupport::MultilanguageSupport()
     }
   }
 
+  // Connect LanguageChangedSignal to clear caches when locale is changed.
+  Dali::Adaptor::Get().LanguageChangedSignal().Connect( mSlotDelegate, &Dali::Toolkit::Text::Internal::MultilanguageSupport::OnLanguageChanged );
+}
+
+void MultilanguageSupport::OnLanguageChanged( Dali::Adaptor& adaptor )
+{
+  // When locale is changed, font configuration might provide a different font list.
+  // In this case, the original cached font might not be valid for same script.
+  // Therefore, we need to clear caches.
+  TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+  fontClient.ClearCache();
+
+  mDefaultFontPerScriptCache.Clear();
+  mValidFontsPerScriptCache.Clear();
+  mDefaultFontPerScriptCache.Resize( TextAbstraction::UNKNOWN + 1, NULL );
+  mValidFontsPerScriptCache.Resize( TextAbstraction::UNKNOWN + 1, NULL );
 }
 
 MultilanguageSupport::~MultilanguageSupport()
index c9a7d30..7fc88a3 100644 (file)
@@ -23,6 +23,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/multi-language-support.h>
+#include <dali/integration-api/adaptors/adaptor.h>
 
 namespace Dali
 {
@@ -133,6 +134,14 @@ public:
    */
   ~MultilanguageSupport();
 
+
+  /**
+   * Dali::MultilanguageSupport::OnLanguageChanged()
+   *
+   * Get notice when system language is changed.
+   */
+  void OnLanguageChanged( Dali::Adaptor& adaptor );
+
   /**
    * @copydoc Dali::MultilanguageSupport::Get()
    */
@@ -159,8 +168,9 @@ public:
                       Vector<FontRun>& fonts );
 
 private:
-  Vector<DefaultFonts*>           mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
-  Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
+  Vector<DefaultFonts*>                  mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
+  Vector<ValidateFontsPerScript*>        mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
+  SlotDelegate< MultilanguageSupport >   mSlotDelegate; //< SlotDelegate to listen LanguageChangedSignal.
 };
 
 } // namespace Internal