Text background support for TextLabel 03/168603/7
authorRichard Huang <r.huang@samsung.com>
Mon, 29 Jan 2018 17:37:12 +0000 (17:37 +0000)
committerRichard Huang <r.huang@samsung.com>
Fri, 16 Feb 2018 14:45:04 +0000 (14:45 +0000)
Change-Id: I62d1d2a5cec9b0f3d1f73859358385d08357c8b4

18 files changed:
automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/devel-api/visuals/text-visual-properties-devel.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/rendering/text-typesetter.cpp
dali-toolkit/internal/text/rendering/view-model.cpp
dali-toolkit/internal/text/rendering/view-model.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h
dali-toolkit/internal/text/text-effects-style.cpp
dali-toolkit/internal/text/text-effects-style.h
dali-toolkit/internal/text/text-model-interface.h
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-model.h
dali-toolkit/internal/text/visual-model-impl.cpp
dali-toolkit/internal/text/visual-model-impl.h
dali-toolkit/internal/visuals/text/text-visual.cpp

index 825e7d4..e0daf86 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -65,6 +65,7 @@ const char* const PROPERTY_NAME_UNDERLINE = "underline";
 const char* const PROPERTY_NAME_SHADOW = "shadow";
 const char* const PROPERTY_NAME_EMBOSS = "emboss";
 const char* const PROPERTY_NAME_OUTLINE = "outline";
+const char* const PROPERTY_NAME_BACKGROUND = "textBackground";
 
 const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize";
 const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis";
@@ -255,6 +256,7 @@ int UtcDaliToolkitTextLabelGetPropertyP(void)
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextLabel::Property::SHADOW );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextLabel::Property::EMBOSS );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextLabel::Property::OUTLINE );
+  DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_BACKGROUND ) == DevelTextLabel::Property::BACKGROUND );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == TextLabel::Property::PIXEL_SIZE );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextLabel::Property::ELLIPSIS );
   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_AUTO_SCROLL_LOOP_DELAY ) == TextLabel::Property::AUTO_SCROLL_LOOP_DELAY );
@@ -534,6 +536,18 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
   DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
 
+  // Check the background property
+  Property::Map backgroundMapSet;
+  Property::Map backgroundMapGet;
+
+  backgroundMapSet["enable"] = true;
+  backgroundMapSet["color"] = Color::RED;
+  label.SetProperty( DevelTextLabel::Property::BACKGROUND, backgroundMapSet );
+
+  backgroundMapGet = label.GetProperty<Property::Map>( DevelTextLabel::Property::BACKGROUND );
+  DALI_TEST_EQUALS( backgroundMapGet.Count(), backgroundMapSet.Count(), TEST_LOCATION );
+  DALI_TEST_EQUALS( DaliTestCheckMaps( backgroundMapGet, backgroundMapSet ), true, TEST_LOCATION );
+
   // Check the pixel size of font
   label.SetProperty( TextLabel::Property::PIXEL_SIZE, 20.f );
   DALI_TEST_EQUALS( label.GetProperty<float>( TextLabel::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
index bf54997..ae541f9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -1128,6 +1128,9 @@ int UtcDaliVisualGetPropertyMap10(void)
   Property::Map outlineMapSet;
   propertyMap.Insert( "outline", outlineMapSet.Add("color", Color::YELLOW).Add("width", 1) );
 
+  Property::Map backgroundMapSet;
+  propertyMap.Insert( "textBackground", backgroundMapSet.Add("enable", true).Add("color", Color::CYAN) );
+
   Visual::Base textVisual = factory.CreateVisual( propertyMap );
 
   Property::Map resultMap;
@@ -1202,6 +1205,13 @@ int UtcDaliVisualGetPropertyMap10(void)
   DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
   DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
 
+  value = resultMap.Find( DevelTextVisual::Property::BACKGROUND, Property::MAP );
+  DALI_TEST_CHECK( value );
+
+  Property::Map backgroundMapGet = value->Get<Property::Map>();
+  DALI_TEST_EQUALS( backgroundMapGet.Count(), backgroundMapSet.Count(), TEST_LOCATION );
+  DALI_TEST_EQUALS( DaliTestCheckMaps( backgroundMapGet, backgroundMapSet ), true, TEST_LOCATION );
+
   END_TEST;
 }
 
index 3238c61..939c08d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_LABEL_DEVEL_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -80,6 +80,20 @@ namespace Property
      * @see VerticalLineAlignment::Type for supported values
      */
     VERTICAL_LINE_ALIGNMENT,
+
+    /**
+     * @brief The default text background parameters.
+     * @details Name "textBackground", type Property::MAP.
+     * @note Use "textBackground" as property name to avoid conflict with Control's "background" property
+     *
+     * The background map contains the following keys:
+     *
+     * | %Property Name       | Type     | Required | Description                                                                                                        |
+     * |----------------------|----------|----------|--------------------------------------------------------------------------------------------------------------------|
+     * | enable               | BOOLEAN  | No       | True to enable the background or false to disable (the default value is false)                                     |
+     * | color                | VECTOR4  | No       | The color of the background (the default value is Color::CYAN)                                                     |
+     */
+    BACKGROUND,
   };
 
 } // namespace Property
index ec80f49..41f3c89 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_DEVEL_API_VISUALS_TEXT_VISUAL_PROPERTIES_DEVEL_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -54,7 +54,12 @@ enum
    * @brief The default outline parameters.
    * @details name "outline", type Property::MAP.
    */
-  OUTLINE               = UNDERLINE + 1
+  OUTLINE               = UNDERLINE + 1,
+
+  /**
+   * @copydoc Dali::Toolkit::DevelTextLabel::Property::BACKGROUND
+   */
+  BACKGROUND            = UNDERLINE + 2,
 };
 
 
index 5eece25..c3607f5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -129,7 +129,8 @@ DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "autoScrollStopMode",
 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount",                 INTEGER, LINE_COUNT                 )
 DALI_PROPERTY_REGISTRATION( Toolkit,           TextLabel, "lineWrapMode",              INTEGER, LINE_WRAP_MODE             )
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection",       INTEGER, TEXT_DIRECTION             )
-DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment",         INTEGER, VERTICAL_LINE_ALIGNMENT    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "verticalLineAlignment",     INTEGER, VERTICAL_LINE_ALIGNMENT    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit,     TextLabel, "textBackground",            MAP,     BACKGROUND                 )
 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor",      Color::BLACK,     TEXT_COLOR     )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorRed",   TEXT_COLOR_RED,   TEXT_COLOR, 0  )
 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit,    TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1  )
@@ -523,6 +524,15 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
         }
         break;
       }
+      case Toolkit::DevelTextLabel::Property::BACKGROUND:
+      {
+        const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
+        if( update )
+        {
+          impl.mTextUpdateNeeded = true;
+        }
+        break;
+      }
     }
 
     // Request relayout when text update is needed. It's necessary to call it
@@ -816,6 +826,11 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         }
         break;
       }
+      case Toolkit::DevelTextLabel::Property::BACKGROUND:
+      {
+        GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
+        break;
+      }
     }
   }
 
index 901c477..faac5ef 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -423,6 +423,16 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec
       // Combine the two buffers
       imageBuffer = CombineImageBuffer( imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight );
     }
+
+    // Generate the background if enabled
+    const bool backgroundEnabled = mModel->IsBackgroundEnabled();
+    if ( backgroundEnabled )
+    {
+      Devel::PixelBuffer backgroundImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_BACKGROUND, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs -1 );
+
+      // Combine the two buffers
+      imageBuffer = CombineImageBuffer( imageBuffer, backgroundImageBuffer, bufferWidth, bufferHeight );
+    }
   }
 
   // Create the final PixelData for the combined image buffer
@@ -705,6 +715,43 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer( const unsigned int bufferWidth
       }
     }
 
+    // Draw the background color from the leftmost glyph to the rightmost glyph
+    if ( style == Typesetter::STYLE_BACKGROUND )
+    {
+      Vector4 backgroundColor = mModel->GetBackgroundColor();
+
+      for( int y = glyphData.verticalOffset + baseline - line.ascender; y < glyphData.verticalOffset + baseline - line.descender; y++ )
+      {
+        if( ( y < 0 ) || ( y > static_cast<int>(bufferHeight - 1) ) )
+        {
+          // Do not write out of bounds.
+          continue;
+        }
+
+        for( int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++ )
+        {
+          if( ( x < 0 ) || ( x > static_cast<int>(bufferWidth - 1) ) )
+          {
+            // Do not write out of bounds.
+            continue;
+          }
+
+          // Always RGBA image for text with styles
+          uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( glyphData.bitmapBuffer.GetBuffer() );
+          uint32_t backgroundPixel = *( bitmapBuffer + y * glyphData.width + x );
+          uint8_t* backgroundPixelBuffer = reinterpret_cast<uint8_t*>( &backgroundPixel );
+
+          // Write the background color to the pixel buffer
+          *( backgroundPixelBuffer ) = static_cast<uint8_t>( backgroundColor.r * 255.f );
+          *( backgroundPixelBuffer + 1u ) = static_cast<uint8_t>( backgroundColor.g * 255.f );
+          *( backgroundPixelBuffer + 2u ) = static_cast<uint8_t>( backgroundColor.b * 255.f );
+          *( backgroundPixelBuffer + 3u ) = static_cast<uint8_t>( backgroundColor.a * 255.f );
+
+          *( bitmapBuffer + y * glyphData.width + x ) = backgroundPixel;
+        }
+      }
+    }
+
     // Increases the vertical offset with the line's descender.
     glyphData.verticalOffset += static_cast<int>( -line.descender );
   }
index 4d87891..3543fce 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -208,6 +208,16 @@ float ViewModel::GetOutlineWidth() const
   return mModel->GetOutlineWidth();
 }
 
+const Vector4& ViewModel::GetBackgroundColor() const
+{
+  return mModel->GetBackgroundColor();
+}
+
+bool ViewModel::IsBackgroundEnabled() const
+{
+  return mModel->IsBackgroundEnabled();
+}
+
 void ViewModel::ElideGlyphs()
 {
   mIsTextElided = false;
index 46c618f..65cf48c 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_VIEW_MODEL_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -193,7 +193,17 @@ public:
    */
   virtual float GetOutlineWidth() const;
 
- /**
+  /**
+   * @copydoc ModelInterface::GetBackgroundColor()
+   */
+  virtual const Vector4& GetBackgroundColor() const;
+
+  /**
+   * @copydoc ModelInterface::IsBackgroundEnabled()
+   */
+  virtual bool IsBackgroundEnabled() const;
+
+/**
    * @brief Does the text elide.
    *
    * It stores a copy of the visible glyphs and removes as many glyphs as needed
index 136770c..8897b33 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -1217,6 +1217,30 @@ unsigned int Controller::GetOutlineWidth() const
   return mImpl->mModel->mVisualModel->GetOutlineWidth();
 }
 
+void Controller::SetBackgroundColor( const Vector4& color )
+{
+  mImpl->mModel->mVisualModel->SetBackgroundColor( color );
+
+  mImpl->RequestRelayout();
+}
+
+const Vector4& Controller::GetBackgroundColor() const
+{
+  return mImpl->mModel->mVisualModel->GetBackgroundColor();
+}
+
+void Controller::SetBackgroundEnabled( bool enabled )
+{
+  mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
+
+  mImpl->RequestRelayout();
+}
+
+bool Controller::IsBackgroundEnabled() const
+{
+  return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
+}
+
 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
 {
   if( NULL == mImpl->mEmbossDefaults )
index 85c6818..b2321c4 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_CONTROLLER_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -870,6 +870,34 @@ public: // Default style & Input style
   unsigned int GetOutlineWidth() const;
 
   /**
+   * @brief Set the background color.
+   *
+   * @param[in] color color of background.
+   */
+  void SetBackgroundColor( const Vector4& color );
+
+  /**
+   * @brief Retrieve the background color.
+   *
+   * @return The background color.
+   */
+  const Vector4& GetBackgroundColor() const;
+
+  /**
+   * @brief Set the background enabled flag.
+   *
+   * @param[in] enabled The background enabled flag.
+   */
+  void SetBackgroundEnabled( bool enabled );
+
+  /**
+   * @brief Returns whether to enable text background or not.
+   *
+   * @return Whether text background is enabled.
+   */
+  bool IsBackgroundEnabled() const;
+
+  /**
    * @brief Sets the emboss's properties string.
    *
    * @note The string is stored to be recovered.
index d8d35de..a3f07d6 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -200,6 +200,34 @@ bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap,
   return 0u == numberOfItems;
 }
 
+bool ParseBackgroundProperties( const Property::Map& backgroundProperties,
+                                bool& enabled,
+                                bool& colorDefined,
+                                Vector4& color )
+{
+  const unsigned int numberOfItems = backgroundProperties.Count();
+
+  // Parses and applies the style.
+  for( unsigned int index = 0u; index < numberOfItems; ++index )
+  {
+    const KeyValuePair& valueGet = backgroundProperties.GetKeyValue( index );
+
+    if( ENABLE_KEY == valueGet.first.stringKey )
+    {
+      /// Enable key.
+      enabled = valueGet.second.Get<bool>();
+    }
+    else if( COLOR_KEY == valueGet.first.stringKey )
+    {
+      /// Color key.
+      colorDefined = true;
+      color = valueGet.second.Get<Vector4>();
+    }
+  }
+
+  return 0u == numberOfItems;
+}
+
 bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
 {
   bool update = false;
@@ -666,6 +694,98 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff
   }
 }
 
+bool SetBackgroundProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
+{
+  bool update = false;
+
+  if( controller )
+  {
+    switch( type )
+    {
+      case EffectStyle::DEFAULT:
+      {
+        const Property::Map& propertiesMap = value.Get<Property::Map>();
+
+        bool enabled = false;
+        bool colorDefined = false;
+        Vector4 color;
+
+        bool empty = true;
+
+        if ( !propertiesMap.Empty() )
+        {
+           empty = ParseBackgroundProperties( propertiesMap,
+                                              enabled,
+                                              colorDefined,
+                                              color );
+        }
+
+        if( !empty )
+        {
+          if( enabled != controller->IsBackgroundEnabled() )
+          {
+            controller->SetBackgroundEnabled( enabled );
+            update = true;
+          }
+
+          if( colorDefined && ( controller->GetBackgroundColor() != color ) )
+          {
+            controller->SetBackgroundColor( color );
+            update = true;
+          }
+        }
+        else
+        {
+          // Disable background.
+          if( controller->IsBackgroundEnabled() )
+          {
+            controller->SetBackgroundEnabled( false );
+            update = true;
+          }
+        }
+        break;
+      }
+      case EffectStyle::INPUT:
+      {
+        // Text background is not supported while inputting yet
+        break;
+      }
+    } // switch
+  } // if( controller )
+
+  return update;
+}
+
+void GetBackgroundProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type )
+{
+  if( controller )
+  {
+    switch( type )
+    {
+      case EffectStyle::DEFAULT:
+      {
+        const bool enabled = controller->IsBackgroundEnabled();
+        const Vector4& color = controller->GetBackgroundColor();
+
+        Property::Map map;
+        map.Insert( ENABLE_KEY, enabled );
+        map.Insert( COLOR_KEY, color );
+
+        value = map;
+
+        break;
+
+      }
+      case EffectStyle::INPUT:
+      {
+        // Text background is not supported while inputting yet
+        break;
+      }
+    }
+  }
+}
+
+
 } // namespace Text
 
 } // namespace Toolkit
index e2b0f0c..240a76e 100755 (executable)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_INTERNAL_TEXT_EFFECTS_STYLE_H__
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -86,6 +86,20 @@ bool ParseOutlineProperties( const Property::Map& outlineProperties,
                                bool& widthDefined,
                                unsigned int& width );
 
+
+/**
+ * @brief Parses the background properties.
+ *
+ * @param[in] backgroundProperties The map with the background properties.
+ * @param[out] enabled Whether the background is enabled.
+ * @param[out] colorDefined Whether the background color is defined.
+ * @param[out] color The background color.
+ */
+bool ParseBackgroundProperties( const Property::Map& backgroundProperties,
+                                bool& enabled,
+                                bool& colorDefined,
+                                Vector4& color );
+
 /**
  * @brief Sets the underline properties.
  *
@@ -166,6 +180,26 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu
  */
 void GetOutlineProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type );
 
+/**
+ * @brief Sets the background properties.
+ *
+ * @param[in] controller The text's controller.
+ * @param[in] value The values of the background's properties.
+ * @param[in] type Whether the property is for the default background or the input background.
+ *
+ * @return Whether the background properties have been updated.
+ */
+bool SetBackgroundProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type );
+
+/**
+ * @brief Retrieves the background's properties.
+ *
+ * @param[in] controller The text's controller.
+ * @param[out] value The value of the underline's properties.
+ * @param[in] type Whether the property is for the default background or the input background.
+ */
+void GetBackgroundProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type );
+
 } // namespace Text
 
 } // namespace Toolkit
index ab21d62..f2a82ad 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_MODEL_INTERFACE_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -240,6 +240,20 @@ public:
    */
   virtual float GetOutlineWidth() const = 0;
 
+  /**
+   * @brief Retrieves the background color.
+   *
+   * @return The background color.
+   */
+  virtual const Vector4& GetBackgroundColor() const = 0;
+
+  /**
+   * @brief Returns whether background is enabled or not.
+   *
+   * @return The background state.
+   */
+  virtual bool IsBackgroundEnabled() const = 0;
+
 };
 
 } // namespace Text
index 7f23aac..84b0428 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -167,6 +167,16 @@ float Model::GetOutlineWidth() const
   return mVisualModel->GetOutlineWidth();
 }
 
+const Vector4& Model::GetBackgroundColor() const
+{
+  return mVisualModel->GetBackgroundColor();
+}
+
+bool Model::IsBackgroundEnabled() const
+{
+  return mVisualModel->IsBackgroundEnabled();
+}
+
 Model::Model()
 : mLogicalModel(),
   mVisualModel(),
index 9422996..cb8d77c 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_MODEL_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -193,6 +193,16 @@ public:
    */
   virtual float GetOutlineWidth() const;
 
+  /**
+   * @copydoc ModelInterface::GetBackgroundColor()
+   */
+  virtual const Vector4& GetBackgroundColor() const;
+
+  /**
+   * @copydoc ModelInterface::IsBackgroundEnabled()
+   */
+  virtual bool IsBackgroundEnabled() const;
+
 private: // Private contructors & copy operator.
 
   /**
index e359dc7..bd567a4 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -378,6 +378,16 @@ void VisualModel::SetOutlineWidth( unsigned int width )
   mOutlineWidth = width;
 }
 
+void VisualModel::SetBackgroundColor( const Vector4& color )
+{
+  mBackgroundColor = color;
+}
+
+void VisualModel::SetBackgroundEnabled( bool enabled )
+{
+  mBackgroundEnabled = enabled;
+}
+
 const Vector4& VisualModel::GetTextColor() const
 {
   return mTextColor;
@@ -423,6 +433,16 @@ unsigned int VisualModel::GetOutlineWidth() const
   return mOutlineWidth;
 }
 
+const Vector4& VisualModel::GetBackgroundColor() const
+{
+  return mBackgroundColor;
+}
+
+bool VisualModel::IsBackgroundEnabled() const
+{
+  return mBackgroundEnabled;
+}
+
 Length VisualModel::GetNumberOfUnderlineRuns() const
 {
   return mUnderlineRuns.Count();
@@ -449,6 +469,7 @@ VisualModel::VisualModel()
   mShadowColor( Color::BLACK ),
   mUnderlineColor( Color::BLACK ),
   mOutlineColor( Color::WHITE ),
+  mBackgroundColor( Color::CYAN ),
   mControlSize(),
   mShadowOffset(),
   mUnderlineHeight( 0.0f ),
@@ -458,7 +479,8 @@ VisualModel::VisualModel()
   mLayoutSize(),
   mCachedLineIndex( 0u ),
   mUnderlineEnabled( false ),
-  mUnderlineColorSet( false )
+  mUnderlineColorSet( false ),
+  mBackgroundEnabled( false )
 {
 }
 
index 24be0c7..1cb6b4d 100755 (executable)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H__
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -329,6 +329,34 @@ public:
    */
   unsigned int GetOutlineWidth() const;
 
+  /**
+   * @brief Sets the text's background color.
+   *
+   * @param[in] color The text's background color.
+   */
+  void SetBackgroundColor( const Vector4& color );
+
+  /**
+   * @brief Retrieves the text's background color.
+   *
+   * @return The text's background color.
+   */
+  const Vector4& GetBackgroundColor() const;
+
+  /**
+   * @brief Sets whether the text has a background or not.
+   *
+   * @param[in] enabled true if the text has a background.
+   */
+  void SetBackgroundEnabled( bool enabled );
+
+  /**
+   * @brief Returns whether the text has a background or not.
+   *
+   * @return whether the text has a background or not.
+   */
+  bool IsBackgroundEnabled() const;
+
 protected:
 
   /**
@@ -366,6 +394,7 @@ public:
   Vector4                mShadowColor;          ///< Color of drop shadow
   Vector4                mUnderlineColor;       ///< Color of underline
   Vector4                mOutlineColor;         ///< Color of outline
+  Vector4                mBackgroundColor;      ///< Color of text background
   Size                   mControlSize;          ///< The size of the UI control.
   Vector2                mShadowOffset;         ///< Offset for drop shadow, 0 indicates no shadow
   float                  mUnderlineHeight;      ///< Fixed height for underline to override font metrics.
@@ -384,6 +413,7 @@ public:
 
   bool                   mUnderlineEnabled:1;   ///< Underline enabled flag
   bool                   mUnderlineColorSet:1;  ///< Has the underline color been explicitly set?
+  bool                   mBackgroundEnabled:1;   ///< Background enabled flag
 };
 
 } // namespace Text
index 2c8121b..ca3d296 100755 (executable)
@@ -61,6 +61,7 @@ const char * const ENABLE_MARKUP_PROPERTY( "enableMarkup" );
 const char * const SHADOW_PROPERTY( "shadow" );
 const char * const UNDERLINE_PROPERTY( "underline" );
 const char * const OUTLINE_PROPERTY( "outline" );
+const char * const BACKGROUND_PROPERTY( "textBackground" );
 
 const Vector4 FULL_TEXTURE_RECT( 0.f, 0.f, 1.f, 1.f );
 
@@ -335,6 +336,10 @@ Dali::Property::Index StringKeyToIndexKey( const std::string& stringKey )
   {
     result = Toolkit::DevelTextVisual::Property::OUTLINE;
   }
+  else if( stringKey == BACKGROUND_PROPERTY )
+  {
+    result = Toolkit::DevelTextVisual::Property::BACKGROUND;
+  }
 
   return result;
 }
@@ -415,6 +420,9 @@ void TextVisual::DoCreatePropertyMap( Property::Map& map ) const
 
   GetOutlineProperties( mController, value, Text::EffectStyle::DEFAULT );
   map.Insert( Toolkit::DevelTextVisual::Property::OUTLINE, value );
+
+  GetBackgroundProperties( mController, value, Text::EffectStyle::DEFAULT );
+  map.Insert( Toolkit::DevelTextVisual::Property::BACKGROUND, value );
 }
 
 void TextVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
@@ -608,6 +616,11 @@ void TextVisual::DoSetProperty( Dali::Property::Index index, const Dali::Propert
       SetOutlineProperties( mController, propertyValue, Text::EffectStyle::DEFAULT );
       break;
     }
+    case Toolkit::DevelTextVisual::Property::BACKGROUND:
+    {
+      SetBackgroundProperties( mController, propertyValue, Text::EffectStyle::DEFAULT );
+      break;
+    }
   }
 }
 
@@ -698,8 +711,9 @@ void TextVisual::UpdateRenderer()
 
       const bool underlineEnabled = mController->GetTextModel()->IsUnderlineEnabled();
       const bool outlineEnabled = ( mController->GetTextModel()->GetOutlineWidth() > Math::MACHINE_EPSILON_1 );
+      const bool backgroundEnabled = mController->GetTextModel()->IsBackgroundEnabled();;
 
-      const bool styleEnabled = ( shadowEnabled || underlineEnabled || outlineEnabled );
+      const bool styleEnabled = ( shadowEnabled || underlineEnabled || outlineEnabled || backgroundEnabled );
 
       TextureSet textureSet = GetTextTexture( relayoutSize, hasMultipleTextColors, containsEmoji, styleEnabled );
       mImpl->mRenderer.SetTextures( textureSet );