[dali_2.3.23] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-effects-style.cpp
index 8d552d4..be4cbfa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // FILE HEADER
 #include <dali-toolkit/internal/text/text-effects-style.h>
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/math/math-utils.h>
+
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/text-controls/text-style-properties-devel.h>
-#include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
+#include <dali-toolkit/internal/text/markup-processor/markup-processor-helper-functions.h>
 #include <dali-toolkit/internal/text/property-string-parser.h>
-#include <dali-toolkit/public-api/text/text-enumerations.h>
 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
 
 namespace Dali
@@ -33,17 +35,16 @@ namespace Text
 {
 namespace
 {
-const std::string COLOR_KEY("color");
-const std::string OFFSET_KEY("offset");
-const std::string BLUR_RADIUS_KEY("blurRadius");
-const std::string WIDTH_KEY("width");
-const std::string HEIGHT_KEY("height");
-const std::string ENABLE_KEY("enable");
-const std::string TYPE_KEY("type");
-const std::string DASH_WIDTH_KEY("dashWidth");
-const std::string DASH_GAP_KEY("dashGap");
-const std::string TRUE_TOKEN("true");
-const std::string FALSE_TOKEN("false");
+const char* COLOR_KEY = "color";
+const char* OFFSET_KEY = "offset";
+const char* BLUR_RADIUS_KEY = "blurRadius";
+const char* WIDTH_KEY = "width";
+const char* HEIGHT_KEY = "height";
+const char* ENABLE_KEY = "enable";
+const char* TYPE_KEY = "type";
+const char* DASH_WIDTH_KEY = "dashWidth";
+const char* DASH_GAP_KEY = "dashGap";
+const char* TRUE_TOKEN = "true";
 } // namespace
 
 bool ParseShadowProperties(const Property::Map& shadowPropertiesMap,
@@ -228,7 +229,11 @@ bool ParseOutlineProperties(const Property::Map& underlinePropertiesMap,
                             bool&                colorDefined,
                             Vector4&             color,
                             bool&                widthDefined,
-                            uint16_t&            width)
+                            uint16_t&            width,
+                            bool&                offsetDefined,
+                            Vector2&             offset,
+                            bool&                blurRadiusDefined,
+                            float&               blurRadius)
 {
   const unsigned int numberOfItems = underlinePropertiesMap.Count();
 
@@ -249,6 +254,36 @@ bool ParseOutlineProperties(const Property::Map& underlinePropertiesMap,
       widthDefined = true;
       width        = static_cast<uint16_t>(valueGet.second.Get<float>());
     }
+    else if((DevelText::Outline::Property::OFFSET == valueGet.first.indexKey) || (OFFSET_KEY == valueGet.first.stringKey))
+    {
+      /// Offset key.
+      offsetDefined = true;
+
+      if(valueGet.second.GetType() == Dali::Property::STRING)
+      {
+        const std::string offsetStr = valueGet.second.Get<std::string>();
+        StringToVector2(offsetStr.c_str(), offsetStr.size(), offset);
+      }
+      else
+      {
+        offset = valueGet.second.Get<Vector2>();
+      }
+    }
+    else if((DevelText::Outline::Property::BLUR_RADIUS == valueGet.first.indexKey) || (BLUR_RADIUS_KEY == valueGet.first.stringKey))
+    {
+      /// Blur radius key.
+      blurRadiusDefined = true;
+
+      if(valueGet.second.GetType() == Dali::Property::STRING)
+      {
+        const std::string blurRadiusStr = valueGet.second.Get<std::string>();
+        blurRadius                      = StringToFloat(blurRadiusStr.c_str());
+      }
+      else
+      {
+        blurRadius = valueGet.second.Get<float>();
+      }
+    }
   }
 
   return 0u == numberOfItems;
@@ -355,8 +390,8 @@ bool SetUnderlineProperties(ControllerPtr controller, const Property::Value& val
       {
         const Property::Map& propertiesMap = value.Get<Property::Map>();
 
-        bool                  enabled       = false;
-        bool                  colorDefined  = false;
+        bool                  enabled      = false;
+        bool                  colorDefined = false;
         Vector4               color;
         bool                  heightDefined = false;
         float                 height        = 0.f;
@@ -611,7 +646,7 @@ bool SetShadowProperties(ControllerPtr controller, const Property::Value& value,
             update = true;
           }
 
-          if(blurRadiusDefined && (controller->GetShadowBlurRadius() != blurRadius))
+          if(blurRadiusDefined && (!Dali::Equals(controller->GetShadowBlurRadius(), blurRadius)))
           {
             controller->SetShadowBlurRadius(blurRadius);
             update = true;
@@ -751,10 +786,14 @@ bool SetOutlineProperties(ControllerPtr controller, const Property::Value& value
       {
         const Property::Map& propertiesMap = value.Get<Property::Map>();
 
-        bool     colorDefined = false;
+        bool     colorDefined  = false;
         Vector4  color;
-        bool     widthDefined = false;
-        uint16_t width        = 0u;
+        bool     widthDefined  = false;
+        uint16_t width         = 0u;
+        bool     offsetDefined = false;
+        Vector2  offset;
+        bool     blurRadiusDefined = false;
+        float    blurRadius;
 
         bool empty = true;
 
@@ -775,7 +814,11 @@ bool SetOutlineProperties(ControllerPtr controller, const Property::Value& value
                                          colorDefined,
                                          color,
                                          widthDefined,
-                                         width);
+                                         width,
+                                         offsetDefined,
+                                         offset,
+                                         blurRadiusDefined,
+                                         blurRadius);
 
           controller->OutlineSetByString(false);
         }
@@ -794,6 +837,18 @@ bool SetOutlineProperties(ControllerPtr controller, const Property::Value& value
             controller->SetOutlineWidth(width);
             update = true;
           }
+
+          if(offsetDefined && (controller->GetOutlineOffset() != offset))
+          {
+            controller->SetOutlineOffset(offset);
+            update = true;
+          }
+
+          if(blurRadiusDefined && (!Dali::Equals(controller->GetOutlineBlurRadius(), blurRadius)))
+          {
+            controller->SetOutlineBlurRadius(blurRadius);
+            update = true;
+          }
         }
         else
         {
@@ -834,12 +889,16 @@ void GetOutlineProperties(ControllerPtr controller, Property::Value& value, Effe
         }
         else
         {
-          const Vector4& color = controller->GetOutlineColor();
-          const uint16_t width = controller->GetOutlineWidth();
+          const Vector4& color      = controller->GetOutlineColor();
+          const uint16_t width      = controller->GetOutlineWidth();
+          const Vector2& offset     = controller->GetOutlineOffset();
+          const float&   blurRadius = controller->GetOutlineBlurRadius();
 
           Property::Map map;
           map.Insert(COLOR_KEY, color);
           map.Insert(WIDTH_KEY, static_cast<int>(width));
+          map.Insert(OFFSET_KEY, offset);
+          map.Insert(BLUR_RADIUS_KEY, blurRadius);
 
           value = map;
 
@@ -976,11 +1035,11 @@ bool SetStrikethroughProperties(ControllerPtr controller, const Property::Value&
             Text::ParsePropertyString(propertyString, parsedStringMap);
 
             empty = ParseStrikethroughProperties(parsedStringMap,
-                                             enabled,
-                                             colorDefined,
-                                             color,
-                                             heightDefined,
-                                             height);
+                                                 enabled,
+                                                 colorDefined,
+                                                 color,
+                                                 heightDefined,
+                                                 height);
 
             controller->StrikethroughSetByString(!empty);
           }
@@ -1057,7 +1116,7 @@ void GetStrikethroughProperties(ControllerPtr controller, Property::Value& value
         if(controller->IsStrikethroughSetByString())
         {
           std::string       strikethroughProperties = "{\"enable\":";
-          const std::string enabledStr          = enabled ? "true" : "false";
+          const std::string enabledStr              = enabled ? "true" : "false";
           strikethroughProperties += "\"" + enabledStr + "\",";
 
           std::string colorStr;
@@ -1092,6 +1151,17 @@ void GetStrikethroughProperties(ControllerPtr controller, Property::Value& value
   }
 }
 
+Underline::Type StringToUnderlineType(const char* const underlineTypeStr)
+{
+  Underline::Type underlineType = Text::Underline::SOLID;
+  Scripting::GetEnumeration<Underline::Type>(underlineTypeStr,
+                                             UNDERLINE_TYPE_STRING_TABLE,
+                                             UNDERLINE_TYPE_STRING_TABLE_COUNT,
+                                             underlineType);
+
+  return underlineType;
+}
+
 } // namespace Text
 
 } // namespace Toolkit