Support span tag: background 63/272263/2
authorabdullah <abdullahhasan10@gmail.com>
Sun, 13 Mar 2022 13:33:05 +0000 (16:33 +0300)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 22 Mar 2022 02:18:36 +0000 (02:18 +0000)
Change-Id: I20cedebe0f9b07b51afedd8c5481409db80c888d

automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp
automated-tests/src/dali-toolkit-internal/utc-Dali-TextField-internal.cpp
automated-tests/src/dali-toolkit-internal/utc-Dali-TextLabel-internal.cpp
dali-toolkit/internal/text/markup-processor-span.cpp
dali-toolkit/internal/text/markup-processor-span.h
dali-toolkit/internal/text/markup-processor.cpp

index c75f754..0af3a34 100644 (file)
@@ -689,6 +689,37 @@ int UtcDaliTextEditorBackgroundTag(void)
   END_TEST;
 }
 
+int UtcDaliTextEditorSpanBackgroundTag(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextEditorSpanBackgroundTag\n");
+
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK(editor);
+
+  editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
+  editor.SetProperty(TextEditor::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
+  application.GetScene().Add(editor);
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextEditor& editorImpl                   = GetImpl(editor);
+  const ColorIndex* const        backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
+
+  DALI_TEST_CHECK(backgroundColorIndicesBuffer);
+
+  //default color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
+
+  //red color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
+
+  //yellow color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliTextEditorTextWithSpan(void)
 {
   ToolkitTestApplication application;
index b73142a..2bc211d 100644 (file)
@@ -773,6 +773,37 @@ int UtcDaliTextFieldBackgroundTag(void)
   END_TEST;
 }
 
+int UtcDaliTextFieldSpanBackgroundTag(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextFieldSpanBackgroundTag\n");
+
+  TextField field = TextField::New();
+  DALI_TEST_CHECK(field);
+
+  field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
+  field.SetProperty(TextField::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
+  application.GetScene().Add(field);
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextField& fieldImpl                    = GetImpl(field);
+  const ColorIndex* const       backgroundColorIndicesBuffer = fieldImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
+
+  DALI_TEST_CHECK(backgroundColorIndicesBuffer);
+
+  //default color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
+
+  //red color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
+
+  //yellow color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliToolkitTextFieldEllipsisInternalAPIs(void)
 {
   ToolkitTestApplication application;
index dd460f2..68c25dd 100644 (file)
@@ -592,6 +592,37 @@ int UtcDaliTextLabelBackgroundTag(void)
   END_TEST;
 }
 
+int UtcDaliTextLabelSpanBackgroundTag(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextLabelSpanBackgroundTag\n");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
+  label.SetProperty(TextLabel::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
+  application.GetScene().Add(label);
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextLabel& labelImpl                    = GetImpl(label);
+  const ColorIndex* const       backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
+
+  DALI_TEST_CHECK(backgroundColorIndicesBuffer);
+
+  //default color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
+
+  //red color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
+
+  //yellow color
+  DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
 {
   ToolkitTestApplication application;
index d7bf5eb..240cd62 100644 (file)
@@ -43,6 +43,7 @@ const std::string XHTML_WIDTH_ATTRIBUTE("font-width");
 const std::string XHTML_SLANT_ATTRIBUTE("font-slant");
 
 const std::string XHTML_COLOR_ATTRIBUTE("text-color");
+const std::string XHTML_BACKGROUND_COLOR_ATTRIBUTE("background-color");
 
 //the underlined character's attributes
 const std::string XHTML_UNDERLINE_COLOR_ATTRIBUTE("u-color");
@@ -56,9 +57,11 @@ void ProcessSpanTag(const Tag&              tag,
                     ColorRun&               colorRun,
                     FontDescriptionRun&     fontRun,
                     UnderlinedCharacterRun& underlinedCharacterRun,
+                    ColorRun&               backgroundColorRun,
                     bool&                   isColorDefined,
                     bool&                   isFontDefined,
-                    bool&                   isUnderlinedCharacterDefined)
+                    bool&                   isUnderlinedCharacterDefined,
+                    bool&                   isBackgroundColorDefined)
 {
   for(Vector<Attribute>::ConstIterator it    = tag.attributes.Begin(),
                                        endIt = tag.attributes.End();
@@ -72,6 +75,11 @@ void ProcessSpanTag(const Tag&              tag,
       isColorDefined = true;
       ProcessColor(attribute, colorRun);
     }
+    else if(TokenComparison(XHTML_BACKGROUND_COLOR_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
+    {
+      isBackgroundColorDefined = true;
+      ProcessColor(attribute, backgroundColorRun);
+    }
     else if(TokenComparison(XHTML_FAMILY_ATTRIBUTE, attribute.nameBuffer, attribute.nameLength))
     {
       isFontDefined = true;
index f5c49f6..d6b514a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_SPAN_H
 
 /*
- * 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.
@@ -34,17 +34,21 @@ struct MarkupProcessData;
  * @param[out] colorRun the color run to be filled.
  * @param[out] fontRun the font run to be filled.
  * @param[out] underlinedCharacterRun the underlined character run to be filled.
+ * @param[out] backgroundColorRun the background color run to be filled.
  * @param[out] isColorDefined if the span has color defined.
  * @param[out] isFontDefined if the span has font defined.
  * @param[out] isUnderlinedCharacterDefined if the span has underlined-character defined.
+ * @param[out] isBackgroundColorDefined if the span has background color defined.
  */
 void ProcessSpanTag(const Tag&              tag,
                     ColorRun&               colorRun,
                     FontDescriptionRun&     fontRun,
                     UnderlinedCharacterRun& underlinedCharacterRun,
+                    ColorRun&               backgroundColorRun,
                     bool&                   isColorDefined,
                     bool&                   isFontDefined,
-                    bool&                   isUnderlinedCharacterDefined);
+                    bool&                   isUnderlinedCharacterDefined,
+                    bool&                   isBackgroundColorDefined);
 
 } // namespace Text
 
index 197dff1..68b0632 100644 (file)
@@ -141,9 +141,11 @@ struct Span
   RunIndex colorRunIndex;
   RunIndex fontRunIndex;
   RunIndex underlinedCharacterRunIndex;
+  RunIndex backgroundColorRunIndex;
   bool     isColorDefined;
   bool     isFontDefined;
   bool     isUnderlinedCharacterDefined;
+  bool     isBackgroundColorDefined;
 };
 
 /**
@@ -203,6 +205,8 @@ void Initialize(Span& span)
   span.isFontDefined                = false;
   span.underlinedCharacterRunIndex  = 0u;
   span.isUnderlinedCharacterDefined = false;
+  span.backgroundColorRunIndex      = 0u;
+  span.isBackgroundColorDefined     = false;
 }
 
 /**
@@ -728,9 +732,11 @@ void ProcessSpanForRun(
   Vector<ColorRun>&               colorRuns,
   Vector<FontDescriptionRun>&     fontRuns,
   Vector<UnderlinedCharacterRun>& underlinedCharacterRuns,
+  Vector<ColorRun>&               backgroundColorRuns,
   RunIndex&                       colorRunIndex,
   RunIndex&                       fontRunIndex,
   RunIndex&                       underlinedCharacterRunIndex,
+  RunIndex&                       backgroundColorRunIndex,
   const CharacterIndex            characterIndex,
   int&                            tagReference)
 {
@@ -746,6 +752,9 @@ void ProcessSpanForRun(
     UnderlinedCharacterRun underlinedCharacterRun;
     Initialize(underlinedCharacterRun);
 
+    ColorRun backgroundColorRun;
+    Initialize(backgroundColorRun);
+
     Span span;
     Initialize(span);
 
@@ -753,12 +762,14 @@ void ProcessSpanForRun(
     colorRun.characterRun.characterIndex               = characterIndex;
     fontRun.characterRun.characterIndex                = characterIndex;
     underlinedCharacterRun.characterRun.characterIndex = characterIndex;
+    backgroundColorRun.characterRun.characterIndex     = characterIndex;
 
     span.colorRunIndex               = colorRunIndex;
     span.fontRunIndex                = fontRunIndex;
     span.underlinedCharacterRunIndex = underlinedCharacterRunIndex;
+    span.backgroundColorRunIndex     = backgroundColorRunIndex;
 
-    ProcessSpanTag(spanTag, colorRun, fontRun, underlinedCharacterRun, span.isColorDefined, span.isFontDefined, span.isUnderlinedCharacterDefined);
+    ProcessSpanTag(spanTag, colorRun, fontRun, underlinedCharacterRun, backgroundColorRun, span.isColorDefined, span.isFontDefined, span.isUnderlinedCharacterDefined, span.isBackgroundColorDefined);
 
     // Push the span into the stack.
     spanStack.Push(span);
@@ -785,6 +796,13 @@ void ProcessSpanForRun(
       ++underlinedCharacterRunIndex;
     }
 
+    if(span.isBackgroundColorDefined)
+    {
+      // Push the run in the logical model.
+      backgroundColorRuns.PushBack(backgroundColorRun);
+      ++backgroundColorRunIndex;
+    }
+
     // Increase reference
     ++tagReference;
   }
@@ -813,6 +831,12 @@ void ProcessSpanForRun(
         underlinedCharacterRun.characterRun.numberOfCharacters = characterIndex - underlinedCharacterRun.characterRun.characterIndex;
       }
 
+      if(span.isBackgroundColorDefined)
+      {
+        ColorRun& backgroundColorRun                       = *(backgroundColorRuns.Begin() + span.backgroundColorRunIndex);
+        backgroundColorRun.characterRun.numberOfCharacters = characterIndex - backgroundColorRun.characterRun.characterIndex;
+      }
+
       --tagReference;
     }
   }
@@ -1072,7 +1096,7 @@ void ProcessMarkupString(const std::string& markupString, MarkupProcessData& mar
       }
       else if(TokenComparison(XHTML_SPAN_TAG, tag.buffer, tag.length))
       {
-        ProcessSpanForRun(tag, spanStack, markupProcessData.colorRuns, markupProcessData.fontRuns, markupProcessData.underlinedCharacterRuns, colorRunIndex, fontRunIndex, underlinedCharacterRunIndex, characterIndex, spanTagReference);
+        ProcessSpanForRun(tag, spanStack, markupProcessData.colorRuns, markupProcessData.fontRuns, markupProcessData.underlinedCharacterRuns, markupProcessData.backgroundColorRuns, colorRunIndex, fontRunIndex, underlinedCharacterRunIndex, backgroundRunIndex, characterIndex, spanTagReference);
       }
       else if(TokenComparison(XHTML_STRIKETHROUGH_TAG, tag.buffer, tag.length))
       {