[Tizen] Add offset to text outline 24/310424/1
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 25 Apr 2024 11:28:13 +0000 (20:28 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Mon, 29 Apr 2024 01:21:11 +0000 (10:21 +0900)
Change-Id: I280ed148384325cfa83e2d48fae15a387bc81fcd
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
20 files changed:
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
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-style-properties-devel.h
dali-toolkit/internal/text/controller/text-controller.cpp
dali-toolkit/internal/text/controller/text-controller.h
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.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-effects-style.cpp
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/text-view-interface.h
dali-toolkit/internal/text/text-view.cpp
dali-toolkit/internal/text/text-view.h
dali-toolkit/internal/text/visual-model-impl.cpp
dali-toolkit/internal/text/visual-model-impl.h

index bc75ce0..c8db163 100644 (file)
@@ -1037,6 +1037,7 @@ int UtcDaliTextEditorSetPropertyP(void)
 
   outlineMapSet["color"] = Color::RED;
   outlineMapSet["width"] = 2.0f;
+  outlineMapSet["offset"] = Vector2(0.0f, 0.0f);
 
   editor.SetProperty(TextEditor::Property::OUTLINE, outlineMapSet);
 
index ccc6bb3..1923880 100644 (file)
@@ -1103,6 +1103,7 @@ int UtcDaliTextFieldSetPropertyP(void)
 
   outlineMapSet["color"] = Color::RED;
   outlineMapSet["width"] = 2.0f;
+  outlineMapSet["offset"] = Vector2(0.0f, 0.0f);
 
   field.SetProperty(TextField::Property::OUTLINE, outlineMapSet);
 
index a45aa41..1a4ce70 100644 (file)
@@ -947,6 +947,7 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
 
   outlineMapSet["color"] = Color::RED;
   outlineMapSet["width"] = 2.0f;
+  outlineMapSet["offset"] = Vector2(2.0f, 2.0f);
   label.SetProperty(TextLabel::Property::OUTLINE, outlineMapSet);
 
   outlineMapGet = label.GetProperty<Property::Map>(TextLabel::Property::OUTLINE);
@@ -956,11 +957,13 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   outlineMapSet.Clear();
   outlineMapSet[Toolkit::DevelText::Outline::Property::COLOR] = Color::BLUE;
   outlineMapSet[Toolkit::DevelText::Outline::Property::WIDTH] = 3.0f;
+  outlineMapSet[Toolkit::DevelText::Outline::Property::OFFSET] = Vector2(3.0f, 3.0f);
+
   label.SetProperty(TextLabel::Property::OUTLINE, outlineMapSet);
 
   outlineMapGet = label.GetProperty<Property::Map>(TextLabel::Property::OUTLINE);
   DALI_TEST_EQUALS(outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION);
-  std::vector<std::string> outlineIndicesConversionTable = {"color", "width"};
+  std::vector<std::string> outlineIndicesConversionTable = {"color", "width", "offset"};
   DALI_TEST_EQUALS(DaliTestCheckMaps(outlineMapGet, outlineMapSet, outlineIndicesConversionTable), true, TEST_LOCATION);
 
   // Check the background property
@@ -1800,6 +1803,7 @@ int UtcDaliToolkitTextlabelTextStyle01(void)
 
   outlineMapSet["color"] = Color::BLUE;
   outlineMapSet["width"] = 2.0f;
+  outlineMapSet["offset"] = "2 2";
   label.SetProperty(TextLabel::Property::OUTLINE, outlineMapSet);
 
   application.SendNotification();
index 5f7d114..bb955c3 100644 (file)
@@ -1290,7 +1290,7 @@ int UtcDaliVisualGetPropertyMap10(void)
   propertyMap.Insert("underline", underlineMapSet.Add("enable", true).Add("color", Color::GREEN).Add("height", 1).Add("type", Text::Underline::Type::SOLID).Add("dashWidth", 2).Add("dashGap", 1));
 
   Property::Map outlineMapSet;
-  propertyMap.Insert("outline", outlineMapSet.Add("color", Color::YELLOW).Add("width", 1));
+  propertyMap.Insert("outline", outlineMapSet.Add("color", Color::YELLOW).Add("width", 1).Add("offset", Vector2(2.0f, 2.0f)));
 
   Property::Map backgroundMapSet;
   propertyMap.Insert("textBackground", backgroundMapSet.Add("enable", true).Add("color", Color::CYAN));
index e3641f6..2e2ed08 100644 (file)
@@ -137,7 +137,14 @@ enum
    * @details Name "width", type Property::STRING or Property::FLOAT i.e. "1.0" or 1.f
    * @note Optional. If not provided then the outline is not enabled.
    */
-  WIDTH
+  WIDTH,
+
+  /**
+   * @brief The offset in pixels of the outline.
+   * @details Name "offset", type Property::STRING or Property::VECTOR2. i.e "3.0 3.0" or Vector2( 3.f, 3.f )
+   * @note Optional. If not provided then the outline is not enabled.
+   */
+  OFFSET
 };
 
 } // namespace Property
index 2f19070..1ee365a 100644 (file)
@@ -973,6 +973,17 @@ float Controller::GetDashedUnderlineGap() const
   return mImpl->mModel->mVisualModel->GetDashedUnderlineGap();
 }
 
+void Controller::SetOutlineOffset(const Vector2& outlineOffset)
+{
+  mImpl->mModel->mVisualModel->SetOutlineOffset(outlineOffset);
+  mImpl->RequestRelayout();
+}
+
+const Vector2& Controller::GetOutlineOffset() const
+{
+  return mImpl->mModel->mVisualModel->GetOutlineOffset();
+}
+
 void Controller::SetOutlineColor(const Vector4& color)
 {
   mImpl->mModel->mVisualModel->SetOutlineColor(color);
index 834d992..c6b80f0 100644 (file)
@@ -1274,6 +1274,20 @@ public: // Default style & Input style
   float GetDashedUnderlineGap() const;
 
   /**
+   * @brief Set the outline offset.
+   *
+   * @param[in] outlineOffset The outline offset.
+   */
+  void SetOutlineOffset(const Vector2& outlineOffset);
+
+  /**
+   * @brief Retrieve the outline offset.
+   *
+   * @return The outline offset.
+   */
+  const Vector2& GetOutlineOffset() const;
+
+  /**
    * @brief Set the outline color.
    *
    * @param[in] color color of outline.
index 5ccaad0..787bcfa 100644 (file)
@@ -450,6 +450,7 @@ struct AtlasRenderer::Impl
     const bool       underlineEnabled = view.IsUnderlineEnabled();
     const uint16_t   outlineWidth     = view.GetOutlineWidth();
     const Vector4&   outlineColor(view.GetOutlineColor());
+    const Vector2&   outlineOffset(view.GetOutlineOffset());
     const bool       isOutline            = 0u != outlineWidth;
     const GlyphInfo* hyphens              = view.GetHyphens();
     const Length*    hyphenIndices        = view.GetHyphenIndices();
@@ -656,7 +657,7 @@ struct AtlasRenderer::Impl
 
         if(0u != slot.mImageId) // invalid slot id, glyph has failed to be added to atlas
         {
-          Vector2 positionPlusOutlineOffset = position;
+          Vector2 positionPlusOutlineOffset = position + outlineOffset;
           if(isOutline)
           {
             // Add an offset to the text.
index 1c31199..f83e7e2 100644 (file)
@@ -1149,11 +1149,15 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer(const uint32_t bufferWidth, con
 
     if(style == Typesetter::STYLE_OUTLINE)
     {
+      const Vector2& outlineOffset = mModel->GetOutlineOffset();
+
       glyphData.horizontalOffset -= outlineWidth;
+      glyphData.horizontalOffset += outlineOffset.x;
       if(lineIndex == 0u)
       {
         // Only need to add the vertical outline offset for the first line
         glyphData.verticalOffset -= outlineWidth;
+        glyphData.verticalOffset += outlineOffset.y;
       }
     }
     else if(style == Typesetter::STYLE_SHADOW)
index 3799fc9..28b4802 100644 (file)
@@ -285,6 +285,11 @@ void ViewModel::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRun
   mModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
 }
 
+const Vector2& ViewModel::GetOutlineOffset() const
+{
+  return mModel->GetOutlineOffset();
+}
+
 const Vector4& ViewModel::GetOutlineColor() const
 {
   return mModel->GetOutlineColor();
index 4de580d..e85dbbc 100644 (file)
@@ -247,6 +247,11 @@ public:
   void GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const override;
 
   /**
+   * @copydoc ModelInterface::GetOutlineOffset()
+   */
+  const Vector2& GetOutlineOffset() const override;
+
+  /**
    * @copydoc ModelInterface::GetOutlineColor()
    */
   const Vector4& GetOutlineColor() const override;
index 2bf1398..60f45d2 100644 (file)
@@ -229,7 +229,9 @@ bool ParseOutlineProperties(const Property::Map& underlinePropertiesMap,
                             bool&                colorDefined,
                             Vector4&             color,
                             bool&                widthDefined,
-                            uint16_t&            width)
+                            uint16_t&            width,
+                            bool&                offsetDefined,
+                            Vector2&             offset)
 {
   const unsigned int numberOfItems = underlinePropertiesMap.Count();
 
@@ -250,6 +252,21 @@ 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>();
+      }
+    }
   }
 
   return 0u == numberOfItems;
@@ -752,10 +769,12 @@ 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 empty = true;
 
@@ -776,7 +795,9 @@ bool SetOutlineProperties(ControllerPtr controller, const Property::Value& value
                                          colorDefined,
                                          color,
                                          widthDefined,
-                                         width);
+                                         width,
+                                         offsetDefined,
+                                         offset);
 
           controller->OutlineSetByString(false);
         }
@@ -795,6 +816,12 @@ bool SetOutlineProperties(ControllerPtr controller, const Property::Value& value
             controller->SetOutlineWidth(width);
             update = true;
           }
+
+          if(offsetDefined && (controller->GetOutlineOffset() != offset))
+          {
+            controller->SetOutlineOffset(offset);
+            update = true;
+          }
         }
         else
         {
@@ -835,12 +862,15 @@ 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();
+
 
           Property::Map map;
           map.Insert(COLOR_KEY, color);
           map.Insert(WIDTH_KEY, static_cast<int>(width));
+          map.Insert(OFFSET_KEY, offset);
 
           value = map;
 
index bd34ff8..8327534 100644 (file)
@@ -322,6 +322,13 @@ public:
   virtual void GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const = 0;
 
   /**
+   * @brief Retrieves the outline offset.
+   *
+   * @return The outline offset.
+   */
+  virtual const Vector2& GetOutlineOffset() const = 0;
+
+  /**
    * @brief Retrieve the outline color.
    *
    * @return The outline color.
index 0f93cb3..008a4fc 100644 (file)
@@ -227,6 +227,11 @@ void Model::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunInde
   mVisualModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
 }
 
+const Vector2& Model::GetOutlineOffset() const
+{
+  return mVisualModel->GetOutlineOffset();
+}
+
 const Vector4& Model::GetOutlineColor() const
 {
   return mVisualModel->GetOutlineColor();
index 012c86f..06b788f 100644 (file)
@@ -245,6 +245,11 @@ public:
   void GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const override;
 
   /**
+   * @copydoc ModelInterface::GetOutlineOffset()
+   */
+  const Vector2& GetOutlineOffset() const override;
+
+  /**
    * @copydoc ModelInterface::GetOutlineColor()
    */
   const Vector4& GetOutlineColor() const override;
index 24fcfff..10ff4ff 100644 (file)
@@ -248,6 +248,13 @@ public:
                                 Length              numberOfRuns) const = 0;
 
   /**
+   * @brief Retrieves the outline offset.
+   *
+   * @return The outline offset.
+   */
+  virtual const Vector2& GetOutlineOffset() const = 0;
+
+  /**
    * @brief Retrieve the outline color.
    *
    * @return The outline color.
index d71000b..66d0af9 100644 (file)
@@ -845,6 +845,18 @@ void View::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns,
   }
 }
 
+const Vector2& View::GetOutlineOffset() const
+{
+// TODO : We should support outline offset to editable text.
+/*
+  if(mImpl->mVisualModel)
+  {
+    return mImpl->mVisualModel->GetOutlineOffset();
+  }
+*/
+  return Vector2::ZERO;
+}
+
 const Vector4& View::GetOutlineColor() const
 {
   if(mImpl->mVisualModel)
index 5bf55e1..9b12d03 100644 (file)
@@ -187,6 +187,11 @@ public:
                                 Length              numberOfRuns) const;
 
   /**
+   * @copydoc Dali::Toolkit::Text::ViewInterface::GetOutlineOffset()
+   */
+  const Vector2& GetOutlineOffset() const override;
+
+  /**
    * @copydoc Dali::Toolkit::Text::ViewInterface::GetOutlineColor()
    */
   const Vector4& GetOutlineColor() const override;
index c79e5a9..1d10383 100644 (file)
@@ -381,6 +381,11 @@ void VisualModel::SetUnderlineColor(const Vector4& color)
   mUnderlineColorSet = true;
 }
 
+void VisualModel::SetOutlineOffset(const Vector2& outlineOffset)
+{
+  mOutlineOffset = outlineOffset;
+}
+
 void VisualModel::SetOutlineColor(const Vector4& color)
 {
   mOutlineColor = color;
@@ -506,6 +511,11 @@ const Vector4& VisualModel::GetUnderlineColor() const
   return mUnderlineColor;
 }
 
+const Vector2& VisualModel::GetOutlineOffset() const
+{
+  return mOutlineOffset;
+}
+
 const Vector4& VisualModel::GetOutlineColor() const
 {
   return mOutlineColor;
@@ -665,6 +675,7 @@ VisualModel::VisualModel()
   mStrikethroughColor(Color::BLACK),
   mControlSize(),
   mShadowOffset(),
+  mOutlineOffset(),
   mUnderlineHeight(0.0f),
   mStrikethroughHeight(0.0f),
   mUnderlineType(Text::Underline::SOLID),
index 9dae2cf..b67172a 100644 (file)
@@ -384,6 +384,13 @@ public:
   Length GetNumberOfUnderlineRuns() const;
 
   /**
+   * @brief Sets the text's outline offset.
+   *
+   * @param[in] outlineOffset The outline offset.
+   */
+  void SetOutlineOffset(const Vector2& outlineOffset);
+
+  /**
    * @brief Set the outline color.
    *
    * @param[in] color color of outline.
@@ -391,6 +398,13 @@ public:
   void SetOutlineColor(const Vector4& color);
 
   /**
+   * @brief Retrieves the text's outline offset.
+   *
+   * @return The text's outline offset.
+   */
+  const Vector2& GetOutlineOffset() const;
+
+  /**
    * @brief Retrieve the outline color.
    *
    * @return The outline color.
@@ -673,6 +687,7 @@ public:
   Vector4                          mStrikethroughColor;     ///< Color of text background
   Size                             mControlSize;            ///< The size of the UI control.
   Vector2                          mShadowOffset;           ///< Offset for drop shadow, 0 indicates no shadow
+  Vector2                          mOutlineOffset;          ///< Offset for outline
   float                            mUnderlineHeight;        ///< Fixed height for underline to override font metrics.
   float                            mStrikethroughHeight;    ///< Fixed height for strikethrough to override font metrics.
   Text::Underline::Type            mUnderlineType;          ///< The type of the underline.