Merge "[4.0] clear cache when locale is changed" into tizen_4.0
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-plugin-impl.cpp
index a1e4cc6..5020d28 100644 (file)
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/text-abstraction/font-list.h>
+
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/integration-api/debug.h>
@@ -91,6 +92,8 @@ const unsigned int NUM_FONT_SLANT_TYPE = sizeof( FONT_SLANT_TYPE_TO_INT ) / size
 
 } // namespace
 
+
+
 using Dali::Vector;
 
 namespace Dali
@@ -230,6 +233,7 @@ FontClient::Plugin::Plugin( unsigned int horizontalDpi,
 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
   mVectorFontCache = new VectorFontCache( mFreeTypeLibrary );
 #endif
+
 }
 
 FontClient::Plugin::~Plugin()
@@ -256,6 +260,35 @@ FontClient::Plugin::~Plugin()
   FT_Done_FreeType( mFreeTypeLibrary );
 }
 
+void FontClient::Plugin::ClearCache()
+{
+  mFontCache.clear();
+  mValidatedFontCache.clear();
+  mFontDescriptionCache.clear();
+  mFontDescriptionCache.resize( 1u );
+
+  mCharacterSetCache.Clear();
+  mCharacterSetCache.Resize( 1u );
+
+  mFontIdCache.clear();
+  mFallbackCache.clear();
+
+#ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
+  if(mVectorFontCache)
+  {
+    mVectorFontCache.clear();
+    mVectorFontCache = NULL;
+  }
+#endif
+
+  mEllipsisCache.Clear();
+  mSystemFonts.clear();
+  mDefaultFonts.clear();
+  mDefaultFontDescriptionCached = false;
+  mDefaultFontCharacterSets.Clear();
+  mDefaultFontDescription = FontDescription();
+}
+
 void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
                                  unsigned int verticalDpi )
 {
@@ -1274,6 +1307,12 @@ bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
   return FT_Err_Ok == error;
 }
 
+bool FontClient::Plugin::AddCustomFontDirectory( const FontPath& path )
+{
+  // NULL as first parameter means the current configuration is used.
+  return FcConfigAppFontAddDir( NULL, reinterpret_cast<const FcChar8 *>( path.c_str() ) );
+}
+
 void FontClient::Plugin::InitSystemFonts()
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" );
@@ -1380,6 +1419,13 @@ FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& f
   // add a property to the pattern for the font family
   FcPatternAddString( fontFamilyPattern, FC_FAMILY, reinterpret_cast<const FcChar8*>( fontDescription.family.c_str() ) );
 
+  // add a property to the pattern for local setting.
+  const char* locale = setlocale( LC_MESSAGES, NULL );
+  if( locale != NULL)
+  {
+    FcPatternAddString( fontFamilyPattern, FC_LANG, reinterpret_cast<const FcChar8*>( locale ) );
+  }
+
   int width = FONT_WIDTH_TYPE_TO_INT[fontDescription.width];
   if( width < 0 )
   {