Spannable-Core: Add SetSpannedText API 07/282807/15
authorssabah <s.sabah@samsung.com>
Tue, 11 Oct 2022 22:30:29 +0000 (01:30 +0300)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 8 Nov 2022 02:24:14 +0000 (11:24 +0900)
  Copy text from Spanned-Text into TextController and apply styles on it.

  void SetSpannedText(TextController textController, const Spanned& spannedText);

  TextController: TextLabel, TextEditor or TextField

  This patch should be preceded by the patch below:
  https://review.tizen.org/gerrit/c/platform/core/uifw/dali-toolkit/+/282806

//Example:

    Dali::Toolkit::Text::SpannableString ss = Dali::Toolkit::Text::SpannableString::New("Hello مرحبا");

    auto isAddedBlue = ss.AttachSpan(
      Dali::Toolkit::Text::ForegroundColorSpan::New(Color::BLUE),
      Dali::Toolkit::Text::Range::New(2u, 4u));

    Dali::Toolkit::Text::SetSpannedText(textLabel, ss);

Change-Id: I03202eb27376d78403050a284a1448f01c4ac120

22 files changed:
automated-tests/src/dali-toolkit-internal/CMakeLists.txt
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp [new file with mode: 0644]
dali-toolkit/devel-api/controls/text-controls/text-spannable.cpp [new file with mode: 0644]
dali-toolkit/devel-api/controls/text-controls/text-spannable.h [new file with mode: 0644]
dali-toolkit/devel-api/file.list
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.h
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-field-impl.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.h
dali-toolkit/internal/file.list
dali-toolkit/internal/text/controller/text-controller-spannable-handler.cpp [new file with mode: 0644]
dali-toolkit/internal/text/controller/text-controller-spannable-handler.h [new file with mode: 0644]
dali-toolkit/internal/text/controller/text-controller-text-updater.cpp
dali-toolkit/internal/text/controller/text-controller.cpp
dali-toolkit/internal/text/controller/text-controller.h
dali-toolkit/internal/text/logical-model-impl.cpp
dali-toolkit/internal/text/logical-model-impl.h
dali-toolkit/internal/text/spannable/spans/base-span-impl.h
dali-toolkit/internal/text/spannable/spans/foreground-color-span-impl.cpp
dali-toolkit/internal/text/spannable/spans/foreground-color-span-impl.h

index ed393f0..f903fbe 100755 (executable)
@@ -30,6 +30,7 @@ SET(TC_SOURCES
  utc-Dali-Text-MultiLanguage.cpp
  utc-Dali-Text-Segmentation.cpp
  utc-Dali-Text-Shaping.cpp
+ utc-Dali-Text-TextSpannable.cpp
  utc-Dali-Text-Typesetter.cpp
  utc-Dali-Text-ViewModel.cpp
  utc-Dali-TextField-internal.cpp
diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp
new file mode 100644 (file)
index 0000000..ebc4041
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <iostream>
+
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-spannable.h>
+#include <dali-toolkit/devel-api/text/spannable-string.h>
+#include <dali-toolkit/devel-api/text/spans/foreground-color-span.h>
+#include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+Text::SpannableString CreateSpannableStringForForegroundColorSpan()
+{
+  Text::SpannableString spannableString = Text::SpannableString::New("Hello مرحبا");
+  DALI_TEST_CHECK(spannableString);
+
+  auto isAddedGreen = spannableString.AttachSpan(
+    Text::ForegroundColorSpan::New(Color::GREEN),
+    Text::Range::New(5u, 7u));
+  DALI_TEST_CHECK(isAddedGreen);
+
+  auto isAddedBlue = spannableString.AttachSpan(
+    Text::ForegroundColorSpan::New(Color::BLUE),
+    Text::Range::New(1u, 2u));
+  DALI_TEST_CHECK(isAddedBlue);
+
+  return spannableString;
+}
+
+void CheckColorIndices(const Text::ColorIndex* const colorIndicesBuffer,
+                       uint32_t                      numberOfIndices,
+                       std::vector<uint32_t>         indicesToCheck,
+                       std::vector<uint32_t>         expectedValues)
+{
+  DALI_TEST_CHECK(colorIndicesBuffer);
+
+  for(uint32_t i = 0u; i < numberOfIndices; i++)
+  {
+    DALI_TEST_EQUALS(colorIndicesBuffer[indicesToCheck[i]], expectedValues[i], TEST_LOCATION);
+  }
+}
+
+int UtcDaliToolkitTextLabelSetSpannedText(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextLabelSetSpannedText");
+
+  TextLabel textLabel = TextLabel::New();
+  DALI_TEST_CHECK(textLabel);
+  application.GetScene().Add(textLabel);
+
+  Text::SpannableString spannableString = CreateSpannableStringForForegroundColorSpan();
+
+  Text::SetSpannedText(textLabel, spannableString);
+
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextLabel& labelImpl           = GetImpl(textLabel);
+  const Text::ColorIndex* const colorIndicesBuffer  = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
+
+  CheckColorIndices(colorIndicesBuffer, 6u, {0u, 1u, 2u, 5u, 7u, 10u}, {0u, 2u, 2u, 1u, 1u, 0u});
+
+  END_TEST;
+}
+
+int UtcDaliToolkitTextEditorSetSpannedText(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextEditorSetSpannedText");
+
+  TextEditor textEditor = TextEditor::New();
+  DALI_TEST_CHECK(textEditor);
+  application.GetScene().Add(textEditor);
+
+  Text::SpannableString spannableString = CreateSpannableStringForForegroundColorSpan();
+
+  Text::SetSpannedText(textEditor, spannableString);
+
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextEditor& labelImpl          = GetImpl(textEditor);
+  const Text::ColorIndex* const  colorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
+
+  CheckColorIndices(colorIndicesBuffer, 6u, {0u, 1u, 2u, 5u, 7u, 10u}, {0u, 2u, 2u, 1u, 1u, 0u});
+
+  END_TEST;
+}
+
+int UtcDaliToolkitTextFieldSetSpannedText(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextFieldSetSpannedText");
+
+  TextField textField = TextField::New();
+  DALI_TEST_CHECK(textField);
+  application.GetScene().Add(textField);
+
+  Text::SpannableString spannableString = CreateSpannableStringForForegroundColorSpan();
+
+  Text::SetSpannedText(textField, spannableString);
+
+  application.SendNotification();
+  application.Render();
+
+  Toolkit::Internal::TextField& labelImpl          = GetImpl(textField);
+  const Text::ColorIndex* const colorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
+
+  CheckColorIndices(colorIndicesBuffer, 6u, {0u, 1u, 2u, 5u, 7u, 10u}, {0u, 2u, 2u, 1u, 1u, 0u});
+
+  END_TEST;
+}
diff --git a/dali-toolkit/devel-api/controls/text-controls/text-spannable.cpp b/dali-toolkit/devel-api/controls/text-controls/text-spannable.cpp
new file mode 100644 (file)
index 0000000..a542718
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/controls/text-controls/text-spannable.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
+#include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+void SetSpannedText(TextLabel textLabel, const Spanned& spannedText)
+{
+  return GetImpl(textLabel).SetSpannedText(spannedText);
+}
+
+void SetSpannedText(TextField textField, const Spanned& spannedText)
+{
+  return GetImpl(textField).SetSpannedText(spannedText);
+}
+
+void SetSpannedText(TextEditor textEditor, const Spanned& spannedText)
+{
+  return GetImpl(textEditor).SetSpannedText(spannedText);
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/devel-api/controls/text-controls/text-spannable.h b/dali-toolkit/devel-api/controls/text-controls/text-spannable.h
new file mode 100644 (file)
index 0000000..ef4fa40
--- /dev/null
@@ -0,0 +1,84 @@
+#ifndef DALI_TOOLKIT_TEXT_TEXT_SPANNABLE_H
+#define DALI_TOOLKIT_TEXT_TEXT_SPANNABLE_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/spanned.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-field.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+/**
+ * @brief Set the @p spannedText into @p textLabel
+ * the spanned text contains content (text) and format (spans with ranges)
+ * the text is copied into text-controller and the spans are applied on ranges
+ *
+ * @note the TEXT in @p textLabel will be replaced with text from @p spannedText
+ * and all the applied styles @p textLabel will be replaced the styles from @p spannedText
+ * in-case there are styles were applied from markup-processor will be removed
+ *
+ *
+ * @param[in] textLabel The instance of TextLabel.
+ * @param[in] spannedText the text with spans.
+ */
+DALI_TOOLKIT_API void SetSpannedText(TextLabel textLabel, const Spanned& spannedText);
+
+/**
+ * @brief Set the @p spannedText into @p textField
+ * the spanned text contains content (text) and format (spans with ranges)
+ * the text is copied into text-controller and the spans are applied on ranges
+ *
+ * @note the TEXT in @p textField will be replaced with text from @p spannedText
+ * and all the applied styles @p textField will be replaced the styles from @p spannedText
+ * in-case there are styles were applied from markup-processor will be removed
+ *
+ *
+ * @param[in] textField The instance of TextField.
+ * @param[in] spannedText the text with spans.
+ */
+DALI_TOOLKIT_API void SetSpannedText(TextField textField, const Spanned& spannedText);
+
+/**
+ * @brief Set the @p spannedText into @p textEditor
+ * the spanned text contains content (text) and format (spans with ranges)
+ * the text is copied into text-controller and the spans are applied on ranges
+ *
+ * @note the TEXT in @p textEditor will be replaced with text from @p spannedText
+ * and all the applied styles @p textEditor will be replaced the styles from @p spannedText
+ * in-case there are styles were applied from markup-processor will be removed
+ *
+ *
+ * @param[in] textEditor The instance of TextEditor.
+ * @param[in] spannedText the text with spans.
+ */
+DALI_TOOLKIT_API void SetSpannedText(TextEditor textEditor, const Spanned& spannedText);
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_TEXT_TEXT_SPANNABLE_H
index 92a1f3a..ef347e7 100755 (executable)
@@ -36,6 +36,7 @@ SET( devel_api_src_files
   ${devel_api_src_dir}/controls/text-controls/text-editor-devel.cpp
   ${devel_api_src_dir}/controls/text-controls/text-field-devel.cpp
   ${devel_api_src_dir}/controls/text-controls/text-label-devel.cpp
+  ${devel_api_src_dir}/controls/text-controls/text-spannable.cpp
   ${devel_api_src_dir}/controls/text-controls/text-selection-popup.cpp
   ${devel_api_src_dir}/controls/text-controls/text-selection-toolbar.cpp
   ${devel_api_src_dir}/controls/tool-bar/tool-bar.cpp
@@ -229,6 +230,7 @@ SET( devel_api_text_controls_header_files
   ${devel_api_src_dir}/controls/text-controls/text-editor-devel.h
   ${devel_api_src_dir}/controls/text-controls/text-field-devel.h
   ${devel_api_src_dir}/controls/text-controls/text-label-devel.h
+  ${devel_api_src_dir}/controls/text-controls/text-spannable.h
   ${devel_api_src_dir}/controls/text-controls/text-selection-popup.h
   ${devel_api_src_dir}/controls/text-controls/text-selection-toolbar.h
   ${devel_api_src_dir}/controls/text-controls/text-style-properties-devel.h
index dae56ef..8520498 100644 (file)
@@ -374,6 +374,11 @@ Rect<float> TextEditor::GetCharacterBoundingRectangle(const uint32_t charIndex)
   return mController->GetCharacterBoundingRectangle(charIndex);
 }
 
+void TextEditor::SetSpannedText(const Text::Spanned& spannedText)
+{
+  mController->SetSpannedText(spannedText);
+}
+
 string TextEditor::GetSelectedText() const
 {
   string selectedText = "";
@@ -904,7 +909,7 @@ void TextEditor::OnTap(const TapGesture& gesture)
   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
 
   Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
-  if (keyboardFocusManager)
+  if(keyboardFocusManager)
   {
     keyboardFocusManager.SetCurrentFocusActor(Self());
   }
@@ -944,7 +949,7 @@ bool TextEditor::OnKeyEvent(const KeyEvent& event)
     if(event.GetState() == KeyEvent::UP)
     {
       Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
-      if (keyboardFocusManager)
+      if(keyboardFocusManager)
       {
         keyboardFocusManager.ClearFocus();
       }
index 71d11c4..062baf4 100644 (file)
 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
 #include <dali-toolkit/internal/text/text-control-interface.h>
-#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
@@ -376,6 +376,15 @@ public:
   Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
 
   /**
+   * @brief Set the @p spannedText into current textEditor
+   * the spanned text contains content (text) and  format (spans with ranges)
+   * the text is copied into text-controller and the spans are applied on ranges
+   *
+   * @param[in] spannedText the text with spans.
+   */
+  void SetSpannedText(const Text::Spanned& spannedText);
+
+  /**
    * @copydoc Text::SelectableControlInterface::GetSelectedText()
    */
   string GetSelectedText() const override;
index 6345f15..2f0b559 100644 (file)
@@ -827,7 +827,7 @@ void TextField::OnTap(const TapGesture& gesture)
   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
 
   Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
-  if (keyboardFocusManager)
+  if(keyboardFocusManager)
   {
     keyboardFocusManager.SetCurrentFocusActor(Self());
   }
@@ -867,7 +867,7 @@ bool TextField::OnKeyEvent(const KeyEvent& event)
     if(event.GetState() == KeyEvent::UP)
     {
       Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
-      if (keyboardFocusManager)
+      if(keyboardFocusManager)
       {
         keyboardFocusManager.ClearFocus();
       }
@@ -1215,6 +1215,11 @@ Rect<float> TextField::GetCharacterBoundingRectangle(const uint32_t charIndex) c
   return mController->GetCharacterBoundingRectangle(charIndex);
 }
 
+void TextField::SetSpannedText(const Text::Spanned& spannedText)
+{
+  mController->SetSpannedText(spannedText);
+}
+
 std::string TextField::TextFieldAccessible::GetName() const
 {
   if(IsHiddenInput())
index ce96286..7b5d2f6 100644 (file)
 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
 #include <dali-toolkit/internal/text/text-control-interface.h>
-#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
@@ -282,7 +282,6 @@ private: // From Control
 
   // From SelectableControlInterface
 public:
-
   /**
    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
    */
@@ -385,6 +384,15 @@ public:
    */
   Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
 
+  /**
+   * @brief Set the @p spannedText into current textField
+   * the spanned text contains content (text) and  format (spans with ranges)
+   * the text is copied into text-controller and the spans are applied on ranges
+   *
+   * @param[in] spannedText the text with spans.
+   */
+  void SetSpannedText(const Text::Spanned& spannedText);
+
 private: // Implementation
   /**
    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
index cb60705..2c379db 100644 (file)
@@ -1246,6 +1246,11 @@ Rect<float> TextLabel::GetCharacterBoundingRectangle(const uint32_t charIndex) c
   return mController->GetCharacterBoundingRectangle(charIndex);
 }
 
+void TextLabel::SetSpannedText(const Text::Spanned& spannedText)
+{
+  mController->SetSpannedText(spannedText);
+}
+
 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
 {
   return GetWholeText();
index b935c84..edf0a20 100644 (file)
 #include <dali/public-api/object/property-map.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/spanned.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
 #include <dali-toolkit/internal/text/text-control-interface.h>
-#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/text-scroller-interface.h>
 #include <dali-toolkit/internal/text/text-scroller.h>
 #include <dali-toolkit/internal/visuals/text/text-visual.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
-
 namespace Dali
 {
 namespace Toolkit
@@ -143,6 +143,15 @@ public:
    */
   Rect<float> GetCharacterBoundingRectangle(const uint32_t charIndex) const;
 
+  /**
+   * @brief Set the @p spannedText into current textLabel
+   * the spanned text contains content (text) and  format (spans with ranges)
+   * the text is copied into text-controller and the spans are applied on ranges
+   *
+   * @param[in] spannedText the text with spans.
+   */
+  void SetSpannedText(const Text::Spanned& spannedText);
+
 private: // From Control
   /**
    * @copydoc Control::OnInitialize()
index 3142983..ac79b42 100644 (file)
@@ -190,6 +190,7 @@ SET( toolkit_src_files
    ${toolkit_src_dir}/text/controller/text-controller-placeholder-handler.cpp
    ${toolkit_src_dir}/text/controller/text-controller-relayouter.cpp
    ${toolkit_src_dir}/text/controller/text-controller-text-updater.cpp
+   ${toolkit_src_dir}/text/controller/text-controller-spannable-handler.cpp
    ${toolkit_src_dir}/text/layouts/layout-engine-helper-functions.cpp
    ${toolkit_src_dir}/text/layouts/layout-engine.cpp
    ${toolkit_src_dir}/text/markup-processor/markup-processor.cpp
diff --git a/dali-toolkit/internal/text/controller/text-controller-spannable-handler.cpp b/dali-toolkit/internal/text/controller/text-controller-spannable-handler.cpp
new file mode 100644 (file)
index 0000000..af765fa
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/text/controller/text-controller-spannable-handler.h>
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <memory.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/controller/text-controller-impl.h>
+#include <dali-toolkit/internal/text/controller/text-controller-text-updater.h>
+#include <dali-toolkit/internal/text/logical-model-impl.h>
+#include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
+
+namespace
+{
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
+#endif
+
+} // namespace
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+void Controller::SpannableHandler::SetSpannedText(Controller& controller, const Text::Spanned& spannedText)
+{
+  // Copy content(text)
+  const std::string& text = spannedText.ToString();
+  Controller::TextUpdater::SetText(controller, text);
+
+  Controller::Impl& impl         = *controller.mImpl;
+  LogicalModelPtr&  logicalModel = impl.mModel->mLogicalModel;
+
+  // Set spanned-text
+  logicalModel->mSpannedTextPlaced = true;
+
+  std::vector<Dali::Toolkit::Text::BaseSpan> spans;
+  std::vector<Dali::Toolkit::Text::Range>    ranges;
+  spannedText.RetrieveAllSpansAndRanges(spans, ranges);
+
+  for(std::vector<Dali::Toolkit::Text::BaseSpan>::size_type i = 0; i < spans.size(); i++)
+  {
+    GetImplementation(spans[i]).CreateStyleCharacterRun(logicalModel, ranges[i]);
+  }
+}
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/text/controller/text-controller-spannable-handler.h b/dali-toolkit/internal/text/controller/text-controller-spannable-handler.h
new file mode 100644 (file)
index 0000000..b420010
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef DALI_TOOLKIT_TEXT_SPANNABLE_HANDLER_H
+#define DALI_TOOLKIT_TEXT_SPANNABLE_HANDLER_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <string>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/controller/text-controller.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Text
+{
+/**
+ * @brief Methods that update the text
+ */
+struct Controller::SpannableHandler
+{
+  /// @copydoc Text::Contoller::SetSpannedText
+  /// @param[in] controller The controller
+  static void SetSpannedText(Controller& controller, const Text::Spanned& spannedText);
+};
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_TEXT_SPANNABLE_HANDLER_H
index ca551eb..de812af 100644 (file)
@@ -675,6 +675,9 @@ void Controller::TextUpdater::ResetText(Controller& controller)
   Controller::Impl& impl         = *controller.mImpl;
   LogicalModelPtr&  logicalModel = impl.mModel->mLogicalModel;
 
+  // Reset spanned-text
+  logicalModel->mSpannedTextPlaced = false;
+
   // Reset buffers.
   logicalModel->mText.Clear();
 
index 9f2384d..2589266 100644 (file)
@@ -35,6 +35,7 @@
 #include <dali-toolkit/internal/text/controller/text-controller-input-properties.h>
 #include <dali-toolkit/internal/text/controller/text-controller-placeholder-handler.h>
 #include <dali-toolkit/internal/text/controller/text-controller-relayouter.h>
+#include <dali-toolkit/internal/text/controller/text-controller-spannable-handler.h>
 #include <dali-toolkit/internal/text/controller/text-controller-text-updater.h>
 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
 #include <dali-toolkit/internal/text/text-geometry.h>
@@ -472,6 +473,11 @@ void Controller::GetText(std::string& text) const
   mImpl->GetText(text);
 }
 
+void Controller::SetSpannedText(const Text::Spanned& spannedText)
+{
+  SpannableHandler::SetSpannedText(*this, spannedText);
+}
+
 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
 {
   PlaceholderHandler::SetPlaceholderText(*this, type, text);
index 511c550..85ebfaa 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/spanned.h>
 #include <dali/devel-api/adaptor-framework/input-method-context.h>
 #include <dali/public-api/events/gesture.h>
 
@@ -753,6 +754,15 @@ public: // Update.
   void GetText(std::string& text) const;
 
   /**
+ * @brief Set the @p spannedText
+ * the spanned text contains content (text) and  format (spans with ranges)
+ * the text is copied into text-controller and the spans are applied on ranges
+ *
+ * @param[in] spannedText the text with spans.
+ */
+  void SetSpannedText(const Text::Spanned& spannedText);
+
+  /**
    * @brief Replaces any placeholder text previously set.
    *
    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
@@ -2084,6 +2094,7 @@ private:
   struct PlaceholderHandler;
   struct Relayouter;
   struct TextUpdater;
+  struct SpannableHandler;
 
   Impl* mImpl;
 };
index b7274c0..a4e5db2 100644 (file)
@@ -658,7 +658,8 @@ LogicalModel::~LogicalModel()
 }
 
 LogicalModel::LogicalModel()
-: mBidirectionalLineIndex(0u)
+: mBidirectionalLineIndex(0u),
+  mSpannedTextPlaced(false)
 {
 }
 
index 0fa3df2..ba67488 100644 (file)
@@ -262,6 +262,7 @@ public:
   Vector<CharacterSpacingCharacterRun>  mCharacterSpacingCharacterRuns; ///< The character-spacing character run from markup-processor.
 
   BidirectionalLineRunIndex mBidirectionalLineIndex; ///< The last fetched bidirectional line info.
+  bool                      mSpannedTextPlaced : 1;  ///< Whether the spanned-text is placed.
 };
 
 } // namespace Text
index 9a3447c..a10902e 100644 (file)
@@ -22,6 +22,7 @@
 #include <memory>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/range.h>
 #include <dali-toolkit/devel-api/text/spans/base-span.h>
 #include <dali-toolkit/internal/text/text-definitions.h>
 #include <dali/public-api/object/base-object.h>
@@ -66,6 +67,15 @@ protected:
    */
   virtual ~BaseSpan();
 
+public: //Methods for internal only
+  /**
+   * @brief Create an instance for specific style character run and add it to its logicalModel run.
+   *
+   * @param[in] logicalModel The logical model.
+   * @param[in] range The range.
+   */
+  virtual void CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const = 0;
+
 }; // class BaseSpan
 
 } // namespace Internal
index aaaa9dc..515ba89 100644 (file)
@@ -73,6 +73,16 @@ void ForegroundColorSpan::SetForegroundColor(Vector4 color)
   mImpl->mForegroundColorDefined = true;
 }
 
+void ForegroundColorSpan::CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const
+{
+  ColorRun colorRun;
+  colorRun.characterRun.characterIndex     = range.GetStartIndex();
+  colorRun.characterRun.numberOfCharacters = range.GetNumberOfIndices();
+
+  colorRun.color = mImpl->mForegroundColor;
+  logicalModel->mColorRuns.PushBack(colorRun);
+}
+
 } // namespace Internal
 
 } // namespace Text
index ae6476c..09f226a 100644 (file)
@@ -23,6 +23,7 @@
 #include <memory>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/logical-model-impl.h>
 #include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
 #include <dali/public-api/math/vector4.h>
 
@@ -84,6 +85,12 @@ public: //Methods. Not intended for application developers
    */
   void SetForegroundColor(Vector4 color);
 
+public: //Methods for internal only
+        /**
+   * @copydoc Dali::Toolkit::Text::BaseSpan::CreateStyleCharacterRun
+   */
+  void CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const override;
+
 private:
   struct Impl;
   std::unique_ptr<Impl> mImpl{nullptr};