Caching FcPattern object when using FcCharSetHasChar 83/179383/4
authorminho.sun <minho.sun@samsung.com>
Thu, 17 May 2018 11:39:53 +0000 (20:39 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 24 May 2018 00:58:19 +0000 (00:58 +0000)
The result of FcCharSetHasChar can be destroyed when destroying
FcPattern object.

Caching FcPattern object when using FcCharSetHasChar function and
destroying it later.

Change-Id: Ie2399a40749350ad410345912513ace26dfe273c
Signed-off-by: minho.sun <minho.sun@samsung.com>
dali/internal/text/text-abstraction/font-client-plugin-impl.cpp
dali/internal/text/text-abstraction/font-client-plugin-impl.h

index faa61f0..14efb7b 100644 (file)
@@ -252,7 +252,7 @@ FontClient::Plugin::~Plugin()
 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
   delete mVectorFontCache;
 #endif
-
+  DestroyMatchedPatterns();
   FT_Done_FreeType( mFreeTypeLibrary );
 }
 
@@ -1955,9 +1955,9 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do
     FcCharSet* characterSet = NULL;
     FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
 
-    FcPatternDestroy( match );
     FcPatternDestroy( pattern );
 
+    mMatchedFcPatternCache.PushBack( match );
     mFontCache[id-1u].mCharacterSet = characterSet;
 
     // Add the path to the cache.
@@ -1977,7 +1977,7 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do
   }
 }
 
-FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) const
+FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description )
 {
   FcCharSet* characterSet = NULL;
 
@@ -1989,14 +1989,22 @@ FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDesc
     FcPattern* match = FcFontMatch( NULL, pattern, &result );
 
     FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
+    mMatchedFcPatternCache.PushBack( match );
 
-    FcPatternDestroy( match );
     FcPatternDestroy( pattern );
   }
 
   return characterSet;
 }
 
+void FontClient::Plugin::DestroyMatchedPatterns()
+{
+  for (auto & object : mMatchedFcPatternCache) {
+    FcPatternDestroy(reinterpret_cast<FcPattern*>(object));
+  }
+  mMatchedFcPatternCache.Clear();
+}
+
 } // namespace Internal
 
 } // namespace TextAbstraction
index 969f160..3ada20c 100644 (file)
@@ -485,7 +485,13 @@ private:
    *
    * @return A character set.
    */
-  _FcCharSet* CreateCharacterSetFromDescription( const FontDescription& description ) const;
+  _FcCharSet* CreateCharacterSetFromDescription( const FontDescription& description );
+
+  /**
+   * @brief Destroy all matched Patterns.
+   *
+   */
+  void DestroyMatchedPatterns();
 
 private:
 
@@ -515,9 +521,9 @@ private:
   CharacterSetList                      mCharacterSetCache;    ///< Caches character set lists for the validated font.
   std::vector<FontIdCacheItem>          mFontIdCache;          ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts.
 
-  VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc.
-
-  Vector<EllipsisItem> mEllipsisCache;      ///< Caches ellipsis glyphs for a particular point size.
+  VectorFontCache* mVectorFontCache;            ///< Separate cache for vector data blobs etc.
+  Vector<EllipsisItem> mEllipsisCache;          ///< Caches ellipsis glyphs for a particular point size.
+  Vector<_FcPattern*>  mMatchedFcPatternCache;  ///< Contain matched FcPattern pointer.
 
   bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not
 };