[Tizen] Separate FontConfig handle 88/320088/1
authorBowon Ryu <bowon.ryu@samsung.com>
Wed, 19 Feb 2025 11:06:54 +0000 (20:06 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Mon, 24 Feb 2025 04:23:36 +0000 (13:23 +0900)
This patch changes FontClient to create and use a handle to FontConfig.
Previously we always used FontConfig globally.
There was no problem because DALi had already recognized and developed this internally.

However, since FontConfig is a library open to the system,
FontConfig may be used by other libs that dali does not know about in the same process,
which may cause Thread safe problems.

Change-Id: Ie603016f08376f9c5ca389069b6c8da7a345d7a2
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
15 files changed:
dali/devel-api/text-abstraction/font-client.cpp
dali/devel-api/text-abstraction/font-client.h
dali/internal/text/text-abstraction/font-client-impl.cpp
dali/internal/text/text-abstraction/font-client-impl.h
dali/internal/text/text-abstraction/plugin/bitmap-font-cache-item.cpp
dali/internal/text/text-abstraction/plugin/bitmap-font-cache-item.h
dali/internal/text/text-abstraction/plugin/font-cache-item-interface.h
dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.cpp
dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.h
dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp
dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h
dali/internal/text/text-abstraction/plugin/font-client-utils.cpp
dali/internal/text/text-abstraction/plugin/font-client-utils.h
dali/internal/text/text-abstraction/plugin/font-face-cache-item.cpp
dali/internal/text/text-abstraction/plugin/font-face-cache-item.h

index 115a0108cbd8fd66b8d9799a2cfc695ae612d424..245f30e34308d4f63f031b4bc0b6570bbeec6bf2 100644 (file)
@@ -298,9 +298,9 @@ bool FontClient::AddCustomFontDirectory(const FontPath& path)
   return GetImplementation(*this).AddCustomFontDirectory(path);
 }
 
-void FontClient::ApplyCustomFontDirectories()
+const FontPathList& FontClient::GetCustomFontDirectories()
 {
-  GetImplementation(*this).ApplyCustomFontDirectories();
+  return GetImplementation(*this).GetCustomFontDirectories();
 }
 
 GlyphIndex FontClient::CreateEmbeddedItem(const EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
index 4a2b21ba0446233d11a3d160cef998a211d39a02..6ea9458420f0c1e5a4c2aff34ac498ca11c671a8 100644 (file)
@@ -514,9 +514,11 @@ public:
   bool AddCustomFontDirectory(const FontPath& path);
 
   /**
-   * @brief Apply custom fonts directories
+   * @brief Gets the custom fonts directories.
+   *
+   * @return list of the custom font paths.
    */
-  void ApplyCustomFontDirectories();
+  const FontPathList& GetCustomFontDirectories();
 
   /**
    * @brief Creates and stores an embedded item and it's metrics.
index 6e47a823de0c78c0fb5f3f58ff445ccdd4a07218..585154c7153bdbe986b347b0a57fdf179beb12e4 100644 (file)
@@ -721,11 +721,11 @@ bool FontClient::AddCustomFontDirectory(const FontPath& path)
   return mPlugin->AddCustomFontDirectory(path);
 }
 
-void FontClient::ApplyCustomFontDirectories()
+const FontPathList& FontClient::GetCustomFontDirectories()
 {
   CreatePlugin();
 
-  return mPlugin->ApplyCustomFontDirectories();
+  return mPlugin->GetCustomFontDirectories();
 }
 
 HarfBuzzFontHandle FontClient::GetHarfBuzzFont(FontId fontId)
index 4652d01184091fa739032c160ab7b82e7e947e7d..aef272b8b765010f4e795e04cded10ec32682598 100644 (file)
@@ -332,9 +332,9 @@ public: // API for Dali::TextAbstraction::FontClient used.
   bool AddCustomFontDirectory(const FontPath& path);
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::ApplyCustomFontDirectories()
+   * @copydoc Dali::TextAbstraction::FontClient::GetCustomFontDirectories()
    */
-  void ApplyCustomFontDirectories();
+  const FontPathList& GetCustomFontDirectories();
 
 public: // API for Dali::TextAbstraction::Internal::FontClient used.
   /**
index addd86079e1dabc7bacbb75ab7a24c37e0b243ad..48e91748b7337707fcb6fa61df9d29b9c08abaef 100644 (file)
@@ -123,7 +123,7 @@ void BitmapFontCacheItem::CreateBitmap(
   }
 }
 
-bool BitmapFontCacheItem::IsCharacterSupported(Character character)
+bool BitmapFontCacheItem::IsCharacterSupported(FcConfig* fontConfig, Character character)
 {
   for(const auto& glyph : font.glyphs)
   {
index 889b5b87cb02853d2b8c6852f756e0e16c903b2a..eb1f1704664d8be04d59bb97340b978655b17ea3 100644 (file)
@@ -72,7 +72,7 @@ struct BitmapFontCacheItem : public FontCacheItemInterface
   /**
    * @copydoc FontCacheItemInterface::IsCharacterSupported()
    */
-  bool IsCharacterSupported(Character character) override;
+  bool IsCharacterSupported(FcConfig* fontConfig, Character character) override;
 
   /**
    * @copydoc FontCacheItemInterface::GetPointSize()
index 01a5d1c69ced6b84a994d3918021736f946ce8f7..6da01dab6c337aa43ebdc6f39cec14eec123b102 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/internal/text/text-abstraction/font-client-impl.h> // for HarfBuzzFontHandle
 
 // EXTERNAL INCLUDES
+#include <fontconfig/fontconfig.h>
 #include <ft2build.h>
 #include FT_FREETYPE_H
 
@@ -66,9 +67,10 @@ struct FontCacheItemInterface
 
   /**
    * Check if the character is supported by this font
+   * @param[in] fontConfig A handle to a FontConfig library instance.
    * @param[in] character The character to test
    */
-  virtual bool IsCharacterSupported(Character character) = 0;
+  virtual bool IsCharacterSupported(FcConfig* fontConfig, Character character) = 0;
 
   /**
    * Get the point size of this font
index a0bc875ab56f7576668f9abdd01463fc2abeb7c6..f21d5ad8484ff5c46abe50a369d6755f74ca1540 100644 (file)
@@ -131,10 +131,10 @@ void DestroyCharacterSets(CharacterSetList& characterSets)
  * @brief Retrieves the fonts present in the platform.
  *
  * @note Need to call FcFontSetDestroy to free the allocated resources.
- *
+ * @param[in] fontConfig A handle to a FontConfig library instance.
  * @return A font fonfig data structure with the platform's fonts.
  */
-_FcFontSet* GetFcFontSet()
+_FcFontSet* GetFcFontSet(FcConfig* fontConfig)
 {
   FcFontSet* fontset = nullptr;
 
@@ -158,7 +158,7 @@ _FcFontSet* GetFcFontSet()
 
       // get a list of fonts
       // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
-      fontset = FcFontList(nullptr /* the default configuration is checked to be up to date, and used */, pattern, objectSet); // Creates a FcFontSet that needs to be destroyed by calling FcFontSetDestroy.
+      fontset = FcFontList(fontConfig, pattern, objectSet); // Creates a FcFontSet that needs to be destroyed by calling FcFontSetDestroy.
 
       // clear up the object set
       FcObjectSetDestroy(objectSet);
@@ -176,21 +176,22 @@ _FcFontSet* GetFcFontSet()
  *
  * @note CharacterSetList is a vector of FcCharSet that are reference counted. It's needed to call FcCharSetDestroy to decrease the reference counter.
  *
+ * @param[in] fontConfig A handle to a FontConfig library instance.
  * @param[in] fontDescription A font description.
  * @param[out] fontList A list of the fonts which are a close match for fontDescription.
  * @param[out] characterSetList A list of character sets which are a close match for fontDescription.
  */
-void SetFontList(const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList)
+void SetFontList(FcConfig* fontConfig, const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList)
 {
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
   fontList.clear();
 
-  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontConfig, fontDescription); // Creates a pattern that needs to be destroyed by calling FcPatternDestroy.
 
   FcResult result = FcResultMatch;
 
   // Match the pattern.
-  FcFontSet* fontSet = FcFontSort(nullptr /* use default configure */,
+  FcFontSet* fontSet = FcFontSort(fontConfig,
                                   fontFamilyPattern,
                                   false /* don't trim */,
                                   nullptr,
@@ -282,7 +283,8 @@ FontClient::Plugin::CacheHandler::FontDescriptionSizeCacheKey::FontDescriptionSi
 
 // CacheHandler
 FontClient::Plugin::CacheHandler::CacheHandler()
-: mDefaultFontDescription(),
+: mFontConfig(nullptr),
+  mDefaultFontDescription(),
   mSystemFonts(),
   mDefaultFonts(),
   mFontIdCache(),
@@ -295,6 +297,7 @@ FontClient::Plugin::CacheHandler::CacheHandler()
   mFontFTFaceCache(),
   mEllipsisCache(),
   mEmbeddedItemCache(),
+  mCustomFontDirectories(),
   mGlyphCacheManager(new GlyphCacheManager(GetMaxNumberOfGlyphCache())),
   mLatestFoundFontDescription(),
   mLatestFoundFontDescriptionId(0u),
@@ -307,6 +310,11 @@ FontClient::Plugin::CacheHandler::CacheHandler()
 FontClient::Plugin::CacheHandler::~CacheHandler()
 {
   ClearCache();
+  if(mFontConfig)
+  {
+    FcConfigDestroy(mFontConfig);
+    mFontConfig = nullptr;
+  }
 }
 
 void FontClient::Plugin::CacheHandler::ClearCache()
@@ -457,12 +465,12 @@ void FontClient::Plugin::CacheHandler::CreateCharacterSet()
 {
   for(const auto& description : mDefaultFonts)
   {
-    mDefaultFontCharacterSets.PushBack(FcCharSetCopy(CreateCharacterSetFromDescription(description)));
+    mDefaultFontCharacterSets.PushBack(FcCharSetCopy(CreateCharacterSetFromDescription(mFontConfig, description)));
   }
 
   for(const auto& description : mFontDescriptionCache)
   {
-    mCharacterSetCache.PushBack(FcCharSetCopy(CreateCharacterSetFromDescription(description)));
+    mCharacterSetCache.PushBack(FcCharSetCopy(CreateCharacterSetFromDescription(mFontConfig, description)));
   }
 
   for(auto& item : mFallbackCache)
@@ -476,7 +484,7 @@ void FontClient::Plugin::CacheHandler::CreateCharacterSet()
 
       for(const auto& description : *(item.fallbackFonts))
       {
-        item.characterSets->PushBack(FcCharSetCopy(CreateCharacterSetFromDescription(description)));
+        item.characterSets->PushBack(FcCharSetCopy(CreateCharacterSetFromDescription(mFontConfig, description)));
       }
     }
   }
@@ -496,7 +504,7 @@ void FontClient::Plugin::CacheHandler::InitSystemFonts()
 {
   if(mSystemFonts.empty())
   {
-    FcFontSet* fontSet = GetFcFontSet(); // Creates a FcFontSet that needs to be destroyed by calling FcFontSetDestroy.
+    FcFontSet* fontSet = GetFcFontSet(mFontConfig); // Creates a FcFontSet that needs to be destroyed by calling FcFontSetDestroy.
 
     if(fontSet)
     {
@@ -549,7 +557,7 @@ void FontClient::Plugin::CacheHandler::InitDefaultFonts()
     fontDescription.width  = DefaultFontWidth();
     fontDescription.weight = DefaultFontWeight();
     fontDescription.slant  = DefaultFontSlant();
-    SetFontList(fontDescription, mDefaultFonts, mDefaultFontCharacterSets);
+    SetFontList(mFontConfig, fontDescription, mDefaultFonts, mDefaultFontCharacterSets);
   }
 }
 
@@ -565,19 +573,18 @@ void FontClient::Plugin::CacheHandler::InitDefaultFontDescription()
     // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
     // FcInitReinitialize resets global Fonconfig state and cache, which can cause race conditions or double free.
     // FcInitLoadConfigAndFonts sets the current default configuration for the library, which is specific to the calling process.
+    if(mFontConfig)
+    {
+      FcConfigDestroy(mFontConfig);
+    }
+    mFontConfig = FcInitLoadConfigAndFonts();
 
-    FcConfig* newConfig = FcInitLoadConfigAndFonts();
-
-    if(newConfig)
+    if(mFontConfig)
     {
       for(auto &path: mCustomFontDirectories)
       {
-        FcConfigAppFontAddDir(newConfig, reinterpret_cast<const FcChar8*>(path.c_str()));
+        FcConfigAppFontAddDir(mFontConfig, reinterpret_cast<const FcChar8*>(path.c_str()));
       }
-
-      FcConfigBuildFonts(newConfig);
-      FcConfigSetCurrent(newConfig);
-      FcConfigDestroy(newConfig);
     }
     else
     {
@@ -588,11 +595,11 @@ void FontClient::Plugin::CacheHandler::InitDefaultFontDescription()
 
     if(nullptr != matchPattern)
     {
-      FcConfigSubstitute(nullptr, matchPattern, FcMatchPattern);
+      FcConfigSubstitute(mFontConfig, matchPattern, FcMatchPattern);
       FcDefaultSubstitute(matchPattern);
 
       FcCharSet* characterSet = nullptr;
-      bool       matched      = MatchFontDescriptionToPattern(matchPattern, mDefaultFontDescription, &characterSet);
+      bool       matched      = MatchFontDescriptionToPattern(mFontConfig, matchPattern, mDefaultFontDescription, &characterSet);
 
       // Caching the default font description
       if(matched)
@@ -750,12 +757,12 @@ void FontClient::Plugin::CacheHandler::ValidateFont(const FontDescription& fontD
   DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_VALIDATE_FONT");
 
   // Create a font pattern.
-  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription);
+  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(mFontConfig, fontDescription);
 
   FontDescription description;
 
   FcCharSet* characterSet = nullptr;
-  bool       matched      = MatchFontDescriptionToPattern(fontFamilyPattern, description, &characterSet);
+  bool       matched      = MatchFontDescriptionToPattern(mFontConfig, fontFamilyPattern, description, &characterSet);
   FcPatternDestroy(fontFamilyPattern);
 
   if(matched && (nullptr != characterSet))
@@ -853,7 +860,7 @@ void FontClient::Plugin::CacheHandler::CacheFallbackFontList(FontDescription&&
   fontList         = new FontList;
   characterSetList = new CharacterSetList;
 
-  SetFontList(fontDescription, *fontList, *characterSetList);
+  SetFontList(mFontConfig, fontDescription, *fontList, *characterSetList);
 #ifdef __APPLE__
   FontDescription appleColorEmoji;
   appleColorEmoji.family = "Apple Color Emoji";
@@ -862,7 +869,7 @@ void FontClient::Plugin::CacheHandler::CacheFallbackFontList(FontDescription&&
   appleColorEmoji.slant  = fontDescription.slant;
   FontList         emojiFontList;
   CharacterSetList emojiCharSetList;
-  SetFontList(appleColorEmoji, emojiFontList, emojiCharSetList);
+  SetFontList(mFontConfig, appleColorEmoji, emojiFontList, emojiCharSetList);
 
   std::move(fontList->begin(), fontList->end(), std::back_inserter(emojiFontList));
   emojiCharSetList.Insert(emojiCharSetList.End(), characterSetList->Begin(), characterSetList->End());
@@ -981,10 +988,10 @@ void FontClient::Plugin::CacheHandler::CacheFontPath(FT_Face ftFace, FontId font
     mFontDescriptionSizeCache.emplace(CacheHandler::FontDescriptionSizeCacheKey(fontDescriptionId, requestedPointSize), fontCacheIndex);
     */
 
-    FcPattern* pattern = CreateFontFamilyPattern(description); // Creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
+    FcPattern* pattern = CreateFontFamilyPattern(mFontConfig, description); // Creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
 
     FcResult   result = FcResultMatch;
-    FcPattern* match  = FcFontMatch(nullptr, pattern, &result); // FcFontMatch creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
+    FcPattern* match  = FcFontMatch(mFontConfig, pattern, &result); // FcFontMatch creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
 
     FcCharSet* characterSet = nullptr;
     FcPatternGetCharSet(match, FC_CHARSET, 0u, &characterSet);
index cb7617763504d5972dc2aa883c5834d8e850029f..3ca7891135c2f35cbda92d1e971a6bee3a4ffd7a 100644 (file)
@@ -459,6 +459,7 @@ private:
   CacheHandler& operator=(const CacheHandler&) = delete;
 
 public:                                    // Cache container list
+  FcConfig*       mFontConfig;             ///< A handle to a FontConfig library instance.
   FontDescription mDefaultFontDescription; ///< Cached default font from the system
 
   FontList         mSystemFonts;              ///< Cached system fonts.
@@ -483,7 +484,7 @@ public:                                    // Cache container list
   std::vector<PixelBufferCacheItem> mPixelBufferCache;  ///< Caches the pixel buffer of a url.
   std::vector<EmbeddedItem>         mEmbeddedItemCache; ///< Cache embedded items.
 
-  std::vector<std::string> mCustomFontDirectories;  ///< Cache custom font directories to recovery upon reinitialization.
+  FontPathList mCustomFontDirectories;  ///< Cache custom font directories to recovery upon reinitialization.
 
 private:                                                 // Member value
   std::unique_ptr<GlyphCacheManager> mGlyphCacheManager; ///< The glyph cache manager. It will cache this face's glyphs.
index b781937cddadb220e84bdc65f97e78bc40dbfa88..7652d5063ba85574e50cfef638a966546feaf180 100644 (file)
@@ -240,9 +240,7 @@ FontClient::Plugin::Plugin(unsigned int horizontalDpi,
   mIsAtlasLimitationEnabled(TextAbstraction::FontClient::DEFAULT_ATLAS_LIMITATION_ENABLED),
   mCurrentMaximumBlockSizeFitInAtlas(TextAbstraction::FontClient::MAX_SIZE_FIT_IN_ATLAS),
   mVectorFontCache(nullptr),
-  mCacheHandler(new CacheHandler()),
-  mCustomFonts(),
-  mIsCustomFontsApplied(false)
+  mCacheHandler(new CacheHandler())
 {
   int error = FT_Init_FreeType(&mFreeTypeLibrary);
   if(FT_Err_Ok != error)
@@ -513,7 +511,7 @@ bool FontClient::Plugin::IsCharacterSupportedByFont(FontId fontId, Character cha
   auto fontCacheItem = const_cast<FontCacheItemInterface*>(GetCachedFontItem(fontId));
   if(fontCacheItem != nullptr)
   {
-    isSupported = fontCacheItem->IsCharacterSupported(character); // May cache
+    isSupported = fontCacheItem->IsCharacterSupported(mCacheHandler->mFontConfig, character); // May cache
   }
 
   DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "  is supported : %s\n", (isSupported ? "true" : "false"));
@@ -1069,31 +1067,13 @@ FontDescription::Type FontClient::Plugin::GetFontType(FontId fontId) const
 
 bool FontClient::Plugin::AddCustomFontDirectory(const FontPath& path)
 {
-  if(!mIsCustomFontsApplied)
-  {
-    if(mCustomFonts.size() > CUSTOM_FONTS_MAX_COUNT)
-    {
-      mCustomFonts.clear();
-    }
-    mCustomFonts.push_back(path);
-
-    if(mCacheHandler)
-    {
-      mCacheHandler->mCustomFontDirectories.push_back(path);
-    }
-  }
-  // nullptr as first parameter means the current configuration is used.
-  return FcConfigAppFontAddDir(nullptr, reinterpret_cast<const FcChar8*>(path.c_str()));
+  mCacheHandler->mCustomFontDirectories.push_back(path);
+  return FcConfigAppFontAddDir(mCacheHandler->mFontConfig, reinterpret_cast<const FcChar8*>(path.c_str()));
 }
 
-void FontClient::Plugin::ApplyCustomFontDirectories()
+const FontPathList& FontClient::Plugin::GetCustomFontDirectories()
 {
-  for(const auto& path : mCustomFonts)
-  {
-    FcConfigAppFontAddDir(nullptr, reinterpret_cast<const FcChar8*>(path.c_str()));
-  }
-  mCustomFonts.clear();
-  mIsCustomFontsApplied = true;
+  return mCacheHandler->mCustomFontDirectories;
 }
 
 HarfBuzzFontHandle FontClient::Plugin::GetHarfBuzzFont(FontId fontId) const
@@ -1402,12 +1382,12 @@ bool FontClient::Plugin::IsScalable(const FontPath& path) const
 bool FontClient::Plugin::IsScalable(const FontDescription& fontDescription) const
 {
   // Create a font pattern.
-  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(mCacheHandler->mFontConfig, fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
 
   FcResult result = FcResultMatch;
 
   // match the pattern
-  FcPattern* match      = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* match      = FcFontMatch(mCacheHandler->mFontConfig, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
   bool       isScalable = false;
 
   if(match)
@@ -1463,12 +1443,12 @@ void FontClient::Plugin::GetFixedSizes(const FontDescription&   fontDescription,
                                        Vector<PointSize26Dot6>& sizes) const
 {
   // Create a font pattern.
-  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* fontFamilyPattern = CreateFontFamilyPattern(mCacheHandler->mFontConfig, fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
 
   FcResult result = FcResultMatch;
 
   // match the pattern
-  FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* match = FcFontMatch(mCacheHandler->mFontConfig, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
 
   if(match)
   {
index 5cdb9723cbda15fefc3fd2bef2a8264c8d76fac3..916644bc42993b1401ab5ccb51516dcd09c65a22 100644 (file)
@@ -308,9 +308,9 @@ public: // Dali::TextAbstraction::FontClient
   bool AddCustomFontDirectory(const FontPath& path);
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::ApplyCustomFontDirectories()
+   * @copydoc Dali::TextAbstraction::FontClient::GetCustomFontDirectories()
    */
-  void ApplyCustomFontDirectories();
+  const FontPathList& GetCustomFontDirectories();
 
 public: // Dali::TextAbstraction::Internal::FontClient
   /**
@@ -417,9 +417,6 @@ private:
 
   struct CacheHandler;
   CacheHandler* mCacheHandler; ///< Seperate cache for font data.
-
-  FontPathList mCustomFonts;
-  bool         mIsCustomFontsApplied : 1;
 };
 
 } // namespace Internal
index a6d56fa9a95fdab7c77c0137443634a6770a7119..adc084149032019386a678d4c086c11db07e4423 100644 (file)
@@ -355,7 +355,7 @@ void ConvertBitmap(TextAbstraction::GlyphBufferData& data, FT_Bitmap& srcBitmap,
   }
 }
 
-FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription)
+FcPattern* CreateFontFamilyPattern(FcConfig* fontConfig, const FontDescription& fontDescription)
 {
   // create the cached font family lookup pattern
   // a pattern holds a set of names, each name refers to a property of the font
@@ -402,7 +402,7 @@ FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription)
   FcPatternAddInteger(fontFamilyPattern, FC_SLANT, slant);
 
   // modify the config, with the mFontFamilyPatterm
-  FcConfigSubstitute(nullptr /* use default configure */, fontFamilyPattern, FcMatchPattern);
+  FcConfigSubstitute(fontConfig, fontFamilyPattern, FcMatchPattern);
 
   // provide default values for unspecified properties in the font pattern
   // e.g. patterns without a specified style or weight are set to Medium
@@ -411,16 +411,16 @@ FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription)
   return fontFamilyPattern;
 }
 
-FcCharSet* CreateCharacterSetFromDescription(const FontDescription& description)
+FcCharSet* CreateCharacterSetFromDescription(FcConfig* fontConfig, const FontDescription& description)
 {
   FcCharSet* characterSet = nullptr;
 
-  FcPattern* pattern = CreateFontFamilyPattern(description); // Creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* pattern = CreateFontFamilyPattern(fontConfig, description); // Creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
 
   if(nullptr != pattern)
   {
     FcResult   result = FcResultMatch;
-    FcPattern* match  = FcFontMatch(nullptr, pattern, &result); // FcFontMatch creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
+    FcPattern* match  = FcFontMatch(fontConfig, pattern, &result); // FcFontMatch creates a new pattern that needs to be destroyed by calling FcPatternDestroy.
 
     FcPatternGetCharSet(match, FC_CHARSET, 0u, &characterSet);
 
@@ -432,12 +432,12 @@ FcCharSet* CreateCharacterSetFromDescription(const FontDescription& description)
   return characterSet;
 }
 
-bool MatchFontDescriptionToPattern(FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet)
+bool MatchFontDescriptionToPattern(FcConfig* fontConfig, FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet)
 {
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
 
   FcResult   result = FcResultMatch;
-  FcPattern* match  = FcFontMatch(nullptr /* use default configure */, pattern, &result); // Creates a new font pattern that needs to be destroyed by calling FcPatternDestroy.
+  FcPattern* match  = FcFontMatch(fontConfig, pattern, &result); // Creates a new font pattern that needs to be destroyed by calling FcPatternDestroy.
 
   const bool matched = nullptr != match;
   DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "  pattern matched : %s\n", (matched ? "true" : "false"));
index e6b5f5f49145fd68c8bdc29609efc37bb5c707d5..a3c9a7120769fe34294fe63b421d2efcffc560f9 100644 (file)
@@ -48,34 +48,37 @@ void ConvertBitmap(TextAbstraction::GlyphBufferData& data,
  *
  * @note Need to call FcPatternDestroy to free the resources.
  *
+ * @param[in] fontConfig A handle to a FontConfig library instance.
  * @param[in] fontDescription The font to cache.
  *
  * @return The pattern.
  */
-FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription);
+FcPattern* CreateFontFamilyPattern(FcConfig* fontConfig, const FontDescription& fontDescription);
 
 /**
  * @brief Creates a character set from a given font's @p description.
  *
  * @note Need to call FcCharSetDestroy to free the resources.
  *
+ * @param[in] fontConfig A handle to a FontConfig library instance.
  * @param[in] description The font's description.
  *
  * @return A character set.
  */
-FcCharSet* CreateCharacterSetFromDescription(const FontDescription& description);
+FcCharSet* CreateCharacterSetFromDescription(FcConfig* fontConfig, const FontDescription& description);
 
 /**
  * @brief Gets the FontDescription which matches the given pattern.
  *
  * @note The reference counter of the @p characterSet has been increased. Call FcCharSetDestroy to decrease it.
  *
+ * @param[in] fontConfig A handle to a FontConfig library instance.
  * @param[in] pattern pattern to match against.
  * @param[out] fontDescription the resultant fontDescription that matched.
  * @param[out] characterSet The character set for that pattern.
  * @return true if match found.
  */
-bool MatchFontDescriptionToPattern(FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet);
+bool MatchFontDescriptionToPattern(FcConfig* fontConfig, FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet);
 
 /**
  * @brief Retrieves a font config object's value from a pattern.
index 18c5b97ba1cb4fb9a145900a1cc29a464317f395..b9e7d9beaaa897e7a546c01f35e09fd7275e4074 100644 (file)
@@ -554,9 +554,10 @@ bool FontFaceCacheItem::IsColorGlyph(GlyphIndex glyphIndex) const
 
 /**
  * Check if the character is supported by this font
+ * @param[in] fontConfig A handle to a FontConfig library instance.
  * @param[in] character The character to test
  */
-bool FontFaceCacheItem::IsCharacterSupported(Character character)
+bool FontFaceCacheItem::IsCharacterSupported(FcConfig* fontConfig, Character character)
 {
   if(nullptr == mCharacterSet)
   {
@@ -580,7 +581,7 @@ bool FontFaceCacheItem::IsCharacterSupported(Character character)
       description.weight = FontWeight::BOLD;
     }
 
-    mCharacterSet = FcCharSetCopy(CreateCharacterSetFromDescription(description));
+    mCharacterSet = FcCharSetCopy(CreateCharacterSetFromDescription(fontConfig, description));
   }
 
   return FcCharSetHasChar(mCharacterSet, character);
index f7ca2eb6aaead0a9141d832740e7a05f15151ec7..6fe80022ff1e48ab9f14ced5f821f670799770aa 100644 (file)
@@ -89,7 +89,7 @@ struct FontFaceCacheItem : public FontCacheItemInterface
   /**
    * @copydoc FontCacheItemInterface::IsCharacterSupported()
    */
-  bool IsCharacterSupported(Character character) override;
+  bool IsCharacterSupported(FcConfig* fontConfig, Character character) override;
 
   /**
    * @copydoc FontCacheItemInterface::GetPointSize()