[Tizen] Add EnsureFontClientCreated to StyleMonitor 00/290400/1
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 21 Mar 2023 02:09:36 +0000 (11:09 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Fri, 24 Mar 2023 04:08:46 +0000 (13:08 +0900)
to prevent a FontClient from being created faster than necessary,
do not create a FontClient in the constructor.

Change-Id: I496c71816f953c769558f23abff11ae03fcef0f8
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali/devel-api/adaptor-framework/style-monitor.cpp
dali/devel-api/adaptor-framework/style-monitor.h
dali/internal/styling/common/style-monitor-impl.cpp
dali/internal/styling/common/style-monitor-impl.h

index 233505a..a65b61b 100644 (file)
@@ -49,6 +49,11 @@ StyleMonitor StyleMonitor::DownCast(BaseHandle handle)
   return StyleMonitor(dynamic_cast<Internal::Adaptor::StyleMonitor*>(handle.GetObjectPtr()));
 }
 
+bool StyleMonitor::EnsureFontClientCreated()
+{
+  return GetImplementation(*this).EnsureFontClientCreated();
+}
+
 std::string StyleMonitor::GetDefaultFontFamily() const
 {
   return GetImplementation(*this).GetDefaultFontFamily();
index 2708eec..fabf58f 100644 (file)
@@ -118,6 +118,15 @@ public: // Creation & Destruction
   static StyleMonitor DownCast(BaseHandle handle);
 
 public: // Style Information
+
+  /**
+   * @brief Ensure the font client has been created.
+   *
+   * If font client doesn't exist, create it and set default values.
+   * @return true if the font client has been created.
+   */
+  bool EnsureFontClientCreated();
+
   /**
    * @brief Retrieves the default font family.
    * @return The default font family.
index 3e9000d..01adfbd 100644 (file)
@@ -83,23 +83,32 @@ Dali::StyleMonitor StyleMonitor::Get()
 StyleMonitor::StyleMonitor()
 : mDefaultFontSize(-1)
 {
-  mFontClient = TextAbstraction::FontClient::Get();
-  GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
-  DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str());
-  mDefaultFontSize = mFontClient.GetDefaultFontSize();
 }
 
 StyleMonitor::~StyleMonitor()
 {
 }
 
+bool StyleMonitor::EnsureFontClientCreated()
+{
+  if(!mFontClient)
+  {
+    mFontClient = TextAbstraction::FontClient::Get();
+    GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
+    DALI_LOG_INFO(gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str());
+    mDefaultFontSize = mFontClient.GetDefaultFontSize();
+  }
+
+  return mFontClient != nullptr ? true : false;
+}
+
 void StyleMonitor::StyleChanged(StyleChange::Type styleChange)
 {
   switch(styleChange)
   {
     case StyleChange::DEFAULT_FONT_CHANGE:
     {
-      if(mFontClient)
+      if(EnsureFontClientCreated())
       {
         mFontClient.ResetSystemDefaults();
         GetSystemDefaultFontFamily(mFontClient, mDefaultFontFamily);
@@ -110,7 +119,10 @@ void StyleMonitor::StyleChanged(StyleChange::Type styleChange)
 
     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
     {
-      mDefaultFontSize = mFontClient.GetDefaultFontSize();
+      if(EnsureFontClientCreated())
+      {
+        mDefaultFontSize = mFontClient.GetDefaultFontSize();
+      }
       break;
     }
 
index 14f8fb5..a8bc511 100644 (file)
@@ -63,6 +63,11 @@ public:
   // Style Information
 
   /**
+   * @copydoc Dali::StyleMonitor::EnsureFontClientCreated()
+   */
+  bool EnsureFontClientCreated();
+
+  /**
    * @copydoc Dali::StyleMonitor::GetDefaultFontFamily() const
    */
   std::string GetDefaultFontFamily() const;