Cache the GetDefaultPlatformFontDescription results 25/51825/3
authorPaul Wisbey <p.wisbey@samsung.com>
Mon, 16 Nov 2015 10:55:59 +0000 (10:55 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Mon, 16 Nov 2015 11:27:59 +0000 (11:27 +0000)
Change-Id: Ic4500ec0b20aa8099190183ba7cbdf73b409a5a3

adaptors/common/style-monitor-impl.cpp
adaptors/common/style-monitor-impl.h
text/dali/devel-api/text-abstraction/font-client.cpp
text/dali/devel-api/text-abstraction/font-client.h
text/dali/internal/text-abstraction/font-client-impl.cpp
text/dali/internal/text-abstraction/font-client-impl.h
text/dali/internal/text-abstraction/font-client-plugin-impl.cpp
text/dali/internal/text-abstraction/font-client-plugin-impl.h

index 8e47cfe..df06e2f 100644 (file)
@@ -104,8 +104,8 @@ StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction
 : mPlatformAbstraction(platformAbstraction),
   mDefaultFontSize(-1)
 {
-  mfontClient = TextAbstraction::FontClient::Get();
-  GetSystemDefaultFontFamily( mfontClient, mDefaultFontFamily );
+  mFontClient = TextAbstraction::FontClient::Get();
+  GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
   mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
 }
@@ -120,7 +120,11 @@ void StyleMonitor::StyleChanged( StyleChange::Type styleChange )
   {
     case StyleChange::DEFAULT_FONT_CHANGE:
     {
-      GetSystemDefaultFontFamily( mfontClient, mDefaultFontFamily );
+      if ( mFontClient )
+      {
+        mFontClient.ResetSystemDefaults();
+        GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
+      }
       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
       break;
     }
index ed448d6..e279a31 100644 (file)
@@ -126,7 +126,7 @@ private:
 
   Integration::PlatformAbstraction& mPlatformAbstraction; ///< Reference to the PlatformAbstraction (for retrieving defaults)
 
-  TextAbstraction::FontClient mfontClient;
+  TextAbstraction::FontClient mFontClient;
   std::string mDefaultFontFamily;        ///< The system default font family
   std::string mDefaultFontStyle;         ///< The default font style
   std::string mUserDefinedThemeFilePath; ///< String containing the user defined theme file path
index f6b8fc9..c508990 100644 (file)
@@ -63,9 +63,9 @@ void FontClient::GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi
   GetImplementation(*this).GetDpi( horizontalDpi, verticalDpi );
 }
 
-void FontClient::SetDefaultFont( const FontDescription& fontDescription )
+void FontClient::ResetSystemDefaults()
 {
-  GetImplementation(*this).SetDefaultFont( fontDescription );
+  GetImplementation(*this).ResetSystemDefaults();
 }
 
 void FontClient::GetDefaultFonts( FontList& defaultFonts )
index f50adb9..262a0cf 100644 (file)
@@ -122,12 +122,11 @@ public:
   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
 
   /**
-   * Set the default font family and its style that should be used by the font client.
-   * The style could be a pair 'font style, font width' or a cluster 'font width, font weight, font slant'.
+   * @brief Called when the user changes the system defaults.
    *
-   * @param[in] fontDescription Description of the default font.
+   * @post Previously cached system defaults are removed.
    */
-  void SetDefaultFont( const FontDescription& fontDescription );
+  void ResetSystemDefaults();
 
   /**
    * @brief Retrieve the list of default fonts supported by the system.
index b77d3bf..01a75e3 100644 (file)
@@ -86,11 +86,11 @@ void FontClient::GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi
   verticalDpi = mDpiVertical;
 }
 
-void FontClient::SetDefaultFont( const FontDescription& fontDescription )
+void FontClient::ResetSystemDefaults()
 {
   CreatePlugin();
 
-  mPlugin->SetDefaultFont( fontDescription );
+  mPlugin->ResetSystemDefaults();
 }
 
 void FontClient::GetDefaultFonts( FontList& defaultFonts )
index 2d5596d..aebdbd7 100644 (file)
@@ -66,9 +66,9 @@ public:
   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
 
   /**
-   * @copydoc Dali::FontClient::SetDefaultFont()
+   * @copydoc Dali::FontClient::ResetSystemDefaults()
    */
-  void SetDefaultFont( const FontDescription& fontDescription );
+  void ResetSystemDefaults();
 
   /**
    * @copydoc Dali::FontClient::GetDefaultFonts()
index 078cf8e..a1edfd4 100644 (file)
@@ -196,13 +196,15 @@ FontClient::Plugin::Plugin( unsigned int horizontalDpi,
 : mFreeTypeLibrary( NULL ),
   mDpiHorizontal( horizontalDpi ),
   mDpiVertical( verticalDpi ),
+  mDefaultFontDescription(),
   mSystemFonts(),
   mDefaultFonts(),
   mFontCache(),
   mValidatedFontCache(),
   mFontDescriptionCache( 1u ),
   mFontIdCache(),
-  mEllipsisCache()
+  mEllipsisCache(),
+  mDefaultFontDescriptionCached( false )
 {
   int error = FT_Init_FreeType( &mFreeTypeLibrary );
   if( FT_Err_Ok != error )
@@ -236,6 +238,11 @@ void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
   mDpiVertical = verticalDpi;
 }
 
+void FontClient::Plugin::ResetSystemDefaults()
+{
+  mDefaultFontDescriptionCached = false;
+}
+
 void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, FontList& fontList )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "FontClient::Plugin::SetFontList family(%s)\n", fontDescription.family.c_str() );
@@ -291,11 +298,6 @@ void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, Fo
   FcPatternDestroy( fontFamilyPattern );
 }
 
-void FontClient::Plugin::SetDefaultFont( const FontDescription& fontDescription )
-{
-  SetFontList( fontDescription, mDefaultFonts );
-}
-
 void FontClient::Plugin::GetDefaultFonts( FontList& defaultFonts )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "FontClient::Plugin::GetDefaultFonts mDefaultFonts(%s)\n", ( mDefaultFonts.empty()?"empty":"valid" ) );
@@ -317,14 +319,25 @@ void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fon
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "FontClient::Plugin::GetDefaultPlatformFontDescription\n");
 
-  FcInitReinitialize(); // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
+  if( !mDefaultFontDescriptionCached )
+  {
+    FcInitReinitialize(); // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
+
+    FcPattern* matchPattern = FcPatternCreate();
+    FcConfigSubstitute(NULL, matchPattern, FcMatchPattern);
+    FcDefaultSubstitute( matchPattern );
 
-  FcPattern* matchPattern = FcPatternCreate();
-  FcConfigSubstitute(NULL, matchPattern, FcMatchPattern);
-  FcDefaultSubstitute( matchPattern );
+    MatchFontDescriptionToPattern( matchPattern, mDefaultFontDescription );
+    FcPatternDestroy( matchPattern );
+
+    mDefaultFontDescriptionCached = true;
+  }
 
-  MatchFontDescriptionToPattern( matchPattern, fontDescription );
-  FcPatternDestroy( matchPattern );
+  fontDescription.path   = mDefaultFontDescription.path;
+  fontDescription.family = mDefaultFontDescription.family;
+  fontDescription.width  = mDefaultFontDescription.width;
+  fontDescription.weight = mDefaultFontDescription.weight;
+  fontDescription.slant  = mDefaultFontDescription.slant;
 }
 
 void FontClient::Plugin::GetSystemFonts( FontList& systemFonts )
index 1d4dfc0..bcfaec1 100644 (file)
@@ -147,6 +147,11 @@ struct FontClient::Plugin
   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
 
   /**
+   * @copydoc Dali::FontClient::ResetSystemDefaults()
+   */
+  void ResetSystemDefaults();
+
+  /**
    * @copydoc Dali::FontClient::SetDefaultFont()
    */
   void SetDefaultFont( const FontDescription& fontDescription );
@@ -398,7 +403,7 @@ private:
                      FontDescriptionId& validatedFontId );
 
   /**
-   * Helper for SetDefaultFont etc.
+   * Helper for GetDefaultFonts etc.
    *
    * @param[in] fontDescription A font description.
    * @param[out] fontList A list of the fonts which are a close match for fontDescription.
@@ -410,6 +415,8 @@ private:
   unsigned int mDpiHorizontal; ///< Horizontal dpi.
   unsigned int mDpiVertical;   ///< Vertical dpi.
 
+  FontDescription mDefaultFontDescription; ///< The cached default font from the system
+
   FontList mSystemFonts;       ///< Cached system fonts.
   FontList mDefaultFonts;      ///< Cached default fonts.
 
@@ -421,6 +428,8 @@ private:
   std::vector<FontIdCacheItem>          mFontIdCache;          ///< Caches font ids for the pairs of font point size and the index to the vector with font descriptions of the validated fonts.
 
   Vector<EllipsisItem> mEllipsisCache;      ///< Caches ellipsis glyphs for a particular point size.
+
+  bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not
 };
 
 } // namespace Internal