[Tizen] Fix coverity issue (Use fontDescription after move)
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / font-client-plugin-impl.cpp
index 6715e54..2c31868 100644 (file)
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali/devel-api/text-abstraction/font-list.h>
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
 #include <dali/integration-api/platform-abstraction.h>
 #include <dali/internal/adaptor/common/adaptor-impl.h>
 #include <dali/internal/imaging/common/image-operations.h>
@@ -75,6 +76,9 @@ Dali::Integration::Log::Filter* gFontClientLogFilter = Dali::Integration::Log::F
 
 namespace
 {
+
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FONT_PERFORMANCE_MARKER, false);
+
 /**
  * Conversion from Fractional26.6 to float
  */
@@ -261,6 +265,61 @@ void FontClient::Plugin::ResetSystemDefaults() const
   mCacheHandler->ResetSystemDefaults();
 }
 
+void FontClient::Plugin::FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily) const
+{
+  mCacheHandler->InitDefaultFontDescription();
+
+  FontFamilyList familyList;
+  familyList.reserve(extraFamilyList.size() + 1);
+
+  for (const auto& fallbackFont : fallbackFamilyList)
+  {
+    FontList*         fontList         = nullptr;
+    CharacterSetList* characterSetList = nullptr;
+    FontDescriptionId fontDescriptionId = 0u;
+    FontDescription fontDescription;
+    fontDescription.family = FontFamily(fallbackFont);
+    fontDescription.weight = DefaultFontWeight();
+    fontDescription.width  = DefaultFontWidth();
+    fontDescription.slant  = DefaultFontSlant();
+
+    if(!mCacheHandler->FindFallbackFontList(fontDescription, fontList, characterSetList))
+    {
+      FontDescription copiedFontDescription = fontDescription;
+      mCacheHandler->CacheFallbackFontList(std::move(copiedFontDescription), fontList, characterSetList);
+    }
+    if(!mCacheHandler->FindValidatedFont(fontDescription, fontDescriptionId))
+    {
+      mCacheHandler->ValidateFont(fontDescription, fontDescriptionId);
+    }
+
+    if(extraFamilyList.empty() && localeFamily.empty())
+    {
+      continue;
+    }
+
+    familyList.clear();
+    familyList.insert(familyList.end(), extraFamilyList.begin(), extraFamilyList.end());
+    if(!localeFamily.empty())
+    {
+      familyList.push_back(localeFamily);
+    }
+
+    for(const auto& font : *fontList)
+    {
+      auto it = std::find(familyList.begin(), familyList.end(), font.family);
+      if(it != familyList.end())
+      {
+        if(!mCacheHandler->FindValidatedFont(font, fontDescriptionId))
+        {
+          mCacheHandler->ValidateFont(font, fontDescriptionId);
+        }
+        familyList.erase(it);
+      }
+    }
+  }
+}
+
 void FontClient::Plugin::GetDefaultPlatformFontDescription(FontDescription& fontDescription) const
 {
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
@@ -482,6 +541,8 @@ FontId FontClient::Plugin::FindFallbackFont(Character              charcode,
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
   FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor);
 
+  DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_FIND_FALLBACKFONT");
+
   // The font id to be returned.
   FontId fontId = 0u;
 
@@ -499,6 +560,13 @@ FontId FontClient::Plugin::FindFallbackFont(Character              charcode,
   DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width]);
   DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant]);
 
+  #if defined(TRACE_ENABLED)
+  if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+  {
+    DALI_LOG_DEBUG_INFO("DALI_TEXT_FIND_FALLBACKFONT : %s -> %s\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str());
+  }
+  #endif
+
   // Check first if the font's description has been queried before.
   FontList*         fontList         = nullptr;
   CharacterSetList* characterSetList = nullptr;
@@ -1016,8 +1084,16 @@ FontId FontClient::Plugin::CreateFont(const FontPath& path,
   DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "                path : [%s]\n", path.c_str());
   DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "  requestedPointSize : %d\n", requestedPointSize);
 
+  DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_CREATE_FONT");
   FontId fontId = 0u;
 
+  #if defined(TRACE_ENABLED)
+  if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+  {
+    DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Face : %s\n", path.c_str());
+  }
+  #endif
+
   // Create & cache new font face
   FT_Face ftFace;
   int     error = FT_New_Face(mFreeTypeLibrary,
@@ -1082,7 +1158,7 @@ FontId FontClient::Plugin::CreateFont(const FontPath& path,
         const float fixedHeight = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].height);
 
         // Create the FreeType font face item to cache.
-        FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, path, requestedPointSize, faceIndex, metrics, fixedSizeIndex, fixedWidth, fixedHeight, hasColorTables);
+        FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics, fixedSizeIndex, fixedWidth, fixedHeight, hasColorTables);
 
         fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
       }
@@ -1124,7 +1200,7 @@ FontId FontClient::Plugin::CreateFont(const FontPath& path,
                             static_cast<float>(ftFace->underline_thickness) * FROM_266);
 
         // Create the FreeType font face item to cache.
-        FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, path, requestedPointSize, faceIndex, metrics);
+        FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics);
 
         fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
       }