Fix text outline property related native TCT
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-effects-style.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 44302d7..ea1b3cf
@@ -35,6 +35,7 @@ namespace
 {
 const std::string COLOR_KEY( "color" );
 const std::string OFFSET_KEY( "offset" );
+const std::string WIDTH_KEY( "width" );
 const std::string HEIGHT_KEY( "height" );
 const std::string ENABLE_KEY( "enable" );
 const std::string TRUE_TOKEN( "true" );
@@ -120,6 +121,36 @@ bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap,
   return 0u == numberOfItems;
 }
 
+bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap,
+                               bool& colorDefined,
+                               Vector4& color,
+                               bool& widthDefined,
+                               float& width )
+{
+  const unsigned int numberOfItems = underlinePropertiesMap.Count();
+
+  // Parses and applies the style.
+  for( unsigned int index = 0u; index < numberOfItems; ++index )
+  {
+    const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index );
+
+    if( COLOR_KEY == valueGet.first.stringKey )
+    {
+      /// Color key.
+      colorDefined = true;
+      color = valueGet.second.Get<Vector4>();
+    }
+    else if( WIDTH_KEY == valueGet.first.stringKey )
+    {
+      /// Width key.
+      widthDefined = true;
+      width = valueGet.second.Get<float>();
+    }
+  }
+
+  return 0u == numberOfItems;
+}
+
 bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
 {
   bool update = false;
@@ -138,12 +169,39 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va
         bool heightDefined = false;
         float height = 0.f;
 
-        const bool empty = ParseUnderlineProperties( propertiesMap,
-                                                     enabled,
-                                                     colorDefined,
-                                                     color,
-                                                     heightDefined,
-                                                     height );
+        bool empty = true;
+
+        if ( propertiesMap.Empty() )
+        {
+          // Map empty so check if a string provided
+          const std::string propertyString = value.Get<std::string>();
+
+          if ( !propertyString.empty() )
+          {
+            Property::Map parsedStringMap;
+            Text::ParsePropertyString( propertyString, parsedStringMap );
+
+            empty = ParseUnderlineProperties( parsedStringMap,
+                                              enabled,
+                                              colorDefined,
+                                              color,
+                                              heightDefined,
+                                              height );
+
+            controller->UnderlineSetByString( !empty);
+          }
+        }
+        else
+        {
+           empty = ParseUnderlineProperties( propertiesMap,
+                                             enabled,
+                                             colorDefined,
+                                             color,
+                                             heightDefined,
+                                             height );
+
+           controller->UnderlineSetByString( false );
+        }
 
         if( !empty )
         {
@@ -202,20 +260,40 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E
         const Vector4& color = controller->GetUnderlineColor();
         const float height = controller->GetUnderlineHeight();
 
-        Property::Map map;
+        if ( controller->IsUnderlineSetByString() )
+        {
+          std::string underlineProperties = "{\"enable\":";
+          const std::string enabledStr = enabled ? "true" : "false";
+          underlineProperties += "\"" + enabledStr + "\",";
+
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          underlineProperties += "\"color\":\"" + colorStr + "\",";
 
-        const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN;
-        map.Insert( ENABLE_KEY, enabledStr );
+          std::string heightStr;
+          FloatToString( height, heightStr );
+          underlineProperties += "\"height\":\"" + heightStr + "\"}";
 
-        std::string colorStr;
-        Vector4ToColorString( color, colorStr );
-        map.Insert( COLOR_KEY, colorStr );
+          value = underlineProperties;
+        }
+        else
+        {
+          Property::Map map;
+
+          const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN;
+          map.Insert( ENABLE_KEY, enabledStr );
 
-        std::string heightStr;
-        FloatToString( height, heightStr );
-        map.Insert( HEIGHT_KEY, heightStr );
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          map.Insert( COLOR_KEY, colorStr );
+
+          std::string heightStr;
+          FloatToString( height, heightStr );
+          map.Insert( HEIGHT_KEY, heightStr );
+
+          value = map;
+        }
 
-        value = map;
         break;
       }
       case EffectStyle::INPUT:
@@ -244,11 +322,35 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value
         bool offsetDefined = false;
         Vector2 offset;
 
-        const bool empty = ParseShadowProperties( propertiesMap,
-                                                  colorDefined,
-                                                  color,
-                                                  offsetDefined,
-                                                  offset );
+        bool empty = true;
+
+        if ( propertiesMap.Empty() )
+        {
+           // Map empty so check if a string provided
+           const std::string propertyString = value.Get<std::string>();
+
+           Property::Map parsedStringMap;
+           Text::ParsePropertyString( propertyString, parsedStringMap );
+
+           empty = ParseShadowProperties( parsedStringMap,
+                                          colorDefined,
+                                          color,
+                                          offsetDefined,
+                                          offset );
+
+           controller->ShadowSetByString( !empty );
+
+        }
+        else
+        {
+          empty = ParseShadowProperties( propertiesMap,
+                                         colorDefined,
+                                         color,
+                                         offsetDefined,
+                                         offset );
+
+          controller->ShadowSetByString( false );
+        }
 
         if( !empty )
         {
@@ -299,17 +401,34 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe
         const Vector4& color = controller->GetShadowColor();
         const Vector2& offset = controller->GetShadowOffset();
 
-        Property::Map map;
+        if ( controller->IsShadowSetByString() )
+        {
+          std::string shadowProperties = "{";
+
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          shadowProperties += "\"color\":\"" + colorStr + "\",";
 
-        std::string colorStr;
-        Vector4ToColorString( color, colorStr );
-        map.Insert( COLOR_KEY, colorStr );
+          std::string offsetStr;
+          Vector2ToString( offset, offsetStr );
+          shadowProperties += "\"offset\":\"" + offsetStr + "\"}";
 
-        std::string offsetStr;
-        Vector2ToString( offset, offsetStr );
-        map.Insert( OFFSET_KEY, offsetStr );
+          value = shadowProperties;
+        }
+        else
+        {
+          Property::Map map;
+
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          map.Insert( COLOR_KEY, colorStr );
 
-        value = map;
+          std::string offsetStr;
+          Vector2ToString( offset, offsetStr );
+          map.Insert( OFFSET_KEY, offsetStr );
+
+          value = map;
+        }
         break;
       }
       case EffectStyle::INPUT:
@@ -375,24 +494,76 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu
 
   if( controller )
   {
-    const std::string properties = value.Get< std::string >();
-
     switch( type )
     {
       case EffectStyle::DEFAULT:
       {
-        // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function.
-        controller->SetDefaultOutlineProperties( properties );
+        const Property::Map& propertiesMap = value.Get<Property::Map>();
+
+        bool colorDefined = false;
+        Vector4 color;
+        bool widthDefined = false;
+        float width = 0.f;
+
+        bool empty = true;
+
+        if ( propertiesMap.Empty() )
+        {
+           // Map empty so check if a string provided
+           // This is purely to maintain backward compatibility, but we don't parse the string to be a property map.
+           const std::string propertyString = value.Get<std::string>();
+
+           // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function.
+           controller->SetDefaultOutlineProperties( propertyString );
+
+           controller->OutlineSetByString( true );
+        }
+        else
+        {
+           empty = ParseOutlineProperties( propertiesMap,
+                                           colorDefined,
+                                           color,
+                                           widthDefined,
+                                           width );
+
+           controller->OutlineSetByString( false );
+        }
+
+        if( !empty )
+        {
+          // Sets the default outline values.
+          if( colorDefined && ( controller->GetOutlineColor() != color ) )
+          {
+            controller->SetOutlineColor( color );
+            update = true;
+          }
+
+          if( widthDefined && ( fabsf( controller->GetOutlineWidth() - width ) > Math::MACHINE_EPSILON_1000 ) )
+          {
+            controller->SetOutlineWidth( width );
+            update = true;
+          }
+        }
+        else
+        {
+          // Disable outline
+          if( fabsf( controller->GetOutlineWidth() ) > Math::MACHINE_EPSILON_1000 )
+          {
+            controller->SetOutlineWidth( 0.0f );
+            update = true;
+          }
+        }
         break;
       }
       case EffectStyle::INPUT:
       {
-        // Stores the input outline's properties string to be recovered by the GetOutlineProperties() function.
-        controller->SetInputOutlineProperties( properties );
+        const std::string& outlineProperties = value.Get<std::string>();
+
+        controller->SetInputOutlineProperties( outlineProperties );
         break;
       }
-    }
-  }
+    } // switch
+  } // if( controller )
 
   return update;
 }
@@ -405,8 +576,30 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff
     {
       case EffectStyle::DEFAULT:
       {
-        value = controller->GetDefaultOutlineProperties();
-        break;
+        if ( controller->IsOutlineSetByString() )
+        {
+          value = controller->GetDefaultOutlineProperties();
+          break;
+        }
+        else
+        {
+          const Vector4& color = controller->GetOutlineColor();
+          const float width = controller->GetOutlineWidth();
+
+          Property::Map map;
+
+          std::string colorStr;
+          Vector4ToColorString( color, colorStr );
+          map.Insert( COLOR_KEY, colorStr );
+
+          std::string widthStr;
+          FloatToString( width, widthStr );
+          map.Insert( WIDTH_KEY, widthStr );
+
+          value = map;
+
+          break;
+        }
       }
       case EffectStyle::INPUT:
       {