Merge "Added style name for styling TextEditor ScrollBar" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-font-style.cpp
index b3b9e84..249157e 100644 (file)
@@ -108,12 +108,20 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu
 {
   if( controller )
   {
-    const std::string style = value.Get< std::string >();
-    DALI_LOG_INFO( gLogFilter, Debug::General, "Text Control %p FONT_STYLE %s\n", controller.Get(), style.c_str() );
-
-    // Parses and applies the style.
     Property::Map map;
-    ParsePropertyString( style, map );
+    if( Property::STRING == value.GetType() )
+    {
+      const std::string& fontStyleProperties = value.Get<std::string>();
+
+      ParsePropertyString( fontStyleProperties, map );
+      controller->FontStyleSetByString( true );
+
+    }
+    else
+    {
+      map = value.Get<Property::Map>();
+      controller->FontStyleSetByString( false );
+    }
 
     if( !map.Empty() )
     {
@@ -238,6 +246,7 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon
   if( controller )
   {
     const bool isDefaultStyle = FontStyle::DEFAULT == type;
+    const bool isSetbyString = controller->IsFontStyleSetByString();
 
     bool weightDefined = false;
     bool widthDefined = false;
@@ -289,22 +298,19 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon
       }
     }
 
-    if( weightDefined || widthDefined || slantDefined )
+    if( !isSetbyString )
     {
-      std::string styleString("{");
+      Property::Map map;
+
       if( weightDefined )
       {
         if( TextAbstraction::FontWeight::NONE != weight )
         {
           const std::string weightStr( GetEnumerationName( weight,
-                                                           FONT_WEIGHT_STRING_TABLE,
-                                                           FONT_WEIGHT_STRING_TABLE_COUNT ) );
+                                                          FONT_WEIGHT_STRING_TABLE,
+                                                          FONT_WEIGHT_STRING_TABLE_COUNT ) );
 
-          styleString += "\"weight\":\"" + weightStr + "\"";
-        }
-        else
-        {
-          weightDefined = false;
+          map.Insert( WEIGHT_KEY, weightStr );
         }
       }
 
@@ -316,15 +322,7 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon
                                                           FONT_WIDTH_STRING_TABLE,
                                                           FONT_WIDTH_STRING_TABLE_COUNT ) );
 
-          if( weightDefined )
-          {
-            styleString += ",";
-          }
-          styleString += "\"width\":\"" + widthStr + "\"";
-        }
-        else
-        {
-          widthDefined = false;
+          map.Insert( WIDTH_KEY, widthStr );
         }
       }
 
@@ -336,30 +334,61 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon
                                                           FONT_SLANT_STRING_TABLE,
                                                           FONT_SLANT_STRING_TABLE_COUNT ) );
 
-          if( weightDefined || widthDefined )
-          {
-            styleString += ",";
-          }
-          styleString += "\"slant\":\"" + slantStr + "\"";
+          map.Insert( SLANT_KEY, slantStr );
         }
-        else
+      }
+
+      value = map;
+    } // SetbyMAP
+    else
+    {
+      std::string fontStyleProperties = "{";
+
+      if( weightDefined )
+      {
+        if( TextAbstraction::FontWeight::NONE != weight )
         {
-          slantDefined = false;
+          const std::string weightStr( GetEnumerationName( weight,
+                                                          FONT_WEIGHT_STRING_TABLE,
+                                                          FONT_WEIGHT_STRING_TABLE_COUNT ) );
+
+          fontStyleProperties += "\"weight\":\"" + weightStr + "\",";
         }
       }
 
-      if( weightDefined || widthDefined || slantDefined )
+      if( widthDefined )
       {
-        styleString += "}";
+        if( TextAbstraction::FontWidth::NONE != width )
+        {
+          const std::string widthStr( GetEnumerationName( width,
+                                                          FONT_WIDTH_STRING_TABLE,
+                                                          FONT_WIDTH_STRING_TABLE_COUNT ) );
+          fontStyleProperties += "\"width\":\"" + widthStr + "\",";
+        }
       }
-      else
+
+      if( slantDefined )
       {
-        styleString.clear();
+        if( TextAbstraction::FontSlant::NONE != slant )
+        {
+          const std::string slantStr( GetEnumerationName( slant,
+                                                          FONT_SLANT_STRING_TABLE,
+                                                          FONT_SLANT_STRING_TABLE_COUNT ) );
+
+          fontStyleProperties += "\"slant\":\"" + slantStr + "\"";
+        }
       }
 
-      value = styleString;
-    }
-  }
+      // If last character is comma, it will be removed.
+      if((*fontStyleProperties.rbegin()) == ',' )
+      {
+        fontStyleProperties = fontStyleProperties.substr( 0, fontStyleProperties.size()-1 );
+      }
+      fontStyleProperties += "}";
+
+      value = fontStyleProperties;
+    } // SetbyString
+  }// controller
 }
 
 FontWeight StringToWeight( const char* const weightStr )