Add IsSpannedTextPlaced 17/285217/4
authorssabah <s.sabah@samsung.com>
Wed, 7 Dec 2022 21:56:10 +0000 (00:56 +0300)
committerssabah <s.sabah@samsung.com>
Sun, 11 Dec 2022 12:52:21 +0000 (15:52 +0300)
  Add API into ModelInterface, ViewModel and Model Classes
  This is to check whether the spanned-text is placed or not.

Change-Id: I9e14ad4985ec941155aaf5d491f839d71ab34bf1

automated-tests/src/dali-toolkit-internal/utc-Dali-Text-TextSpannable.cpp
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.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-model-interface.h
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-model.h
dali-toolkit/internal/visuals/text/text-visual.cpp

index 098e660..1f71000 100644 (file)
 #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>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
 #include <dali-toolkit/internal/text/font-description-run.h>
+#include <dali-toolkit/internal/text/rendering/text-typesetter.h>
+#include <dali-toolkit/internal/text/rendering/view-model.h>
+#include <dali-toolkit/internal/text/text-view.h>
 #include <dali-toolkit/public-api/text/text-enumerations.h>
+#include <toolkit-text-utils.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -38,7 +43,7 @@ using namespace Toolkit;
 namespace
 {
 const std::string DEFAULT_FONT_DIR("/resources/fonts");
-const float PIXEL_FORMAT_64_FACTOR = 64.f; ///< 64.f is used to convert from point size to 26.6 pixel format.
+const float       PIXEL_FORMAT_64_FACTOR = 64.f; ///< 64.f is used to convert from point size to 26.6 pixel format.
 } // namespace
 
 Text::SpannableString CreateSpannableStringForForegroundColorSpan()
@@ -100,8 +105,8 @@ int UtcDaliToolkitTextLabelSetSpannedText(void)
   application.SendNotification();
   application.Render();
 
-  Toolkit::Internal::TextLabel& labelImpl           = GetImpl(textLabel);
-  const Text::ColorIndex* const colorIndicesBuffer  = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
+  Toolkit::Internal::TextLabel& labelImpl          = GetImpl(textLabel);
+  const Text::ColorIndex* const colorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
 
   CheckColorIndices(colorIndicesBuffer, 4u, {0u, 5u, 7u, 10u}, {0u, 1u, 1u, 0u});
 
@@ -182,7 +187,7 @@ int UtcDaliToolkitTextLabelSetSpannedText_FontSpan(void)
   application.SendNotification();
   application.Render();
 
-  Toolkit::Internal::TextLabel&               labelImpl  = GetImpl(textLabel);
+  Toolkit::Internal::TextLabel&               labelImpl     = GetImpl(textLabel);
   const Vector<Dali::Toolkit::Text::FontRun>& validFontRuns = labelImpl.GetTextController()->GetTextModel()->GetFontRuns();
 
   DALI_TEST_EQUALS(validFontRuns.Count(), 3u, TEST_LOCATION);
@@ -212,4 +217,89 @@ int UtcDaliToolkitTextLabelSetSpannedText_FontSpan(void)
   DALI_TEST_EQUALS(validFontDescriptionRuns[0].slant, Dali::TextAbstraction::FontSlant::OBLIQUE, TEST_LOCATION);
 
   END_TEST;
+}
+
+int UtcDaliTextModelIsSpannedTextPlaced(void)
+
+{
+  tet_infoline(" UtcDaliTextModelIsSpannedTextPlaced");
+
+  ToolkitTestApplication application;
+
+  // Create spanned-text and set it
+  Text::SpannableString spannedText = Text::SpannableString::New("Hello مرحبا");
+  DALI_TEST_CHECK(spannedText);
+
+  // Creates a text controller.
+  Dali::Toolkit::Text::ControllerPtr         controllerTextEditor = Dali::Toolkit::Text::Controller::New();
+  const Dali::Toolkit::Text::ModelInterface* modelEditor          = controllerTextEditor->GetTextModel();
+
+  // Tests the rendering controller has been created.
+  Dali::Toolkit::Text::TypesetterPtr typesetterEditor = Dali::Toolkit::Text::Typesetter::New(controllerTextEditor->GetTextModel());
+  DALI_TEST_CHECK(typesetterEditor);
+
+  // Tests the view model has been created.
+  Dali::Toolkit::Text::ViewModel* viewModelEditor = typesetterEditor->GetViewModel();
+  DALI_TEST_CHECK(viewModelEditor);
+
+  // Configures the text controller similarly to the text-editor.
+  Dali::Toolkit::Text::ConfigureTextEditor(controllerTextEditor);
+
+  DALI_TEST_EQUALS(false, modelEditor->IsSpannedTextPlaced(), TEST_LOCATION);
+  DALI_TEST_EQUALS(false, viewModelEditor->IsSpannedTextPlaced(), TEST_LOCATION);
+
+  controllerTextEditor->SetSpannedText(spannedText);
+
+  DALI_TEST_EQUALS(true, modelEditor->IsSpannedTextPlaced(), TEST_LOCATION);
+  DALI_TEST_EQUALS(true, viewModelEditor->IsSpannedTextPlaced(), TEST_LOCATION);
+
+  // Creates a text controller.
+  Dali::Toolkit::Text::ControllerPtr         controllerTextLabel = Dali::Toolkit::Text::Controller::New();
+  const Dali::Toolkit::Text::ModelInterface* modelLabel          = controllerTextLabel->GetTextModel();
+
+  // Tests the rendering controller has been created.
+  Dali::Toolkit::Text::TypesetterPtr typesetterLabel = Dali::Toolkit::Text::Typesetter::New(controllerTextLabel->GetTextModel());
+  DALI_TEST_CHECK(typesetterLabel);
+
+  // Tests the view model has been created.
+  Dali::Toolkit::Text::ViewModel* viewModelLabel = typesetterLabel->GetViewModel();
+  DALI_TEST_CHECK(viewModelLabel);
+
+  // Configures the text controller similarly to the text-label.
+  Dali::Toolkit::Text::ConfigureTextLabel(controllerTextLabel);
+
+  DALI_TEST_EQUALS(false, modelLabel->IsSpannedTextPlaced(), TEST_LOCATION);
+  DALI_TEST_EQUALS(false, viewModelLabel->IsSpannedTextPlaced(), TEST_LOCATION);
+
+  controllerTextLabel->SetSpannedText(spannedText);
+
+  DALI_TEST_EQUALS(true, modelLabel->IsSpannedTextPlaced(), TEST_LOCATION);
+  DALI_TEST_EQUALS(true, viewModelLabel->IsSpannedTextPlaced(), TEST_LOCATION);
+
+  // Creates a text controller.
+  Dali::Toolkit::Text::ControllerPtr         controllerTextField = Dali::Toolkit::Text::Controller::New();
+  const Dali::Toolkit::Text::ModelInterface* modelField          = controllerTextField->GetTextModel();
+
+  // Tests the rendering controller has been created.
+  Dali::Toolkit::Text::TypesetterPtr typesetterField = Dali::Toolkit::Text::Typesetter::New(controllerTextField->GetTextModel());
+  DALI_TEST_CHECK(typesetterField);
+
+  // Tests the view model has been created.
+  Dali::Toolkit::Text::ViewModel* viewModelField = typesetterField->GetViewModel();
+  DALI_TEST_CHECK(viewModelField);
+
+  // Configures the text controller similarly to the text-field.
+  Dali::Toolkit::Text::ConfigureTextField(controllerTextField);
+
+  DALI_TEST_EQUALS(false, modelField->IsSpannedTextPlaced(), TEST_LOCATION);
+  DALI_TEST_EQUALS(false, viewModelField->IsSpannedTextPlaced(), TEST_LOCATION);
+
+  controllerTextField->SetSpannedText(spannedText);
+
+  DALI_TEST_EQUALS(true, modelField->IsSpannedTextPlaced(), TEST_LOCATION);
+  DALI_TEST_EQUALS(true, viewModelField->IsSpannedTextPlaced(), TEST_LOCATION);
+
+  tet_result(TET_PASS);
+
+  END_TEST;
 }
\ No newline at end of file
index 80f8092..b13fcda 100755 (executable)
 
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include <toolkit-text-utils.h>
-#include <dali-toolkit/internal/text/font-description-run.h>
+#include <dali-toolkit/devel-api/text/spannable-string.h>
 #include <dali-toolkit/internal/text/controller/text-controller.h>
+#include <dali-toolkit/internal/text/font-description-run.h>
 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
 #include <dali-toolkit/internal/text/rendering/view-model.h>
+#include <toolkit-text-utils.h>
 
 using namespace Dali;
 using namespace Toolkit;
index 73ae2c5..343f6cb 100644 (file)
@@ -1052,7 +1052,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
       }
 
       // Markup-Processor for overlay styles
-      if(mModel->IsMarkupProcessorEnabled())
+      if(mModel->IsMarkupProcessorEnabled() || mModel->IsSpannedTextPlaced())
       {
         if(mModel->IsMarkupUnderlineSet())
         {
index e743b36..725f945 100644 (file)
@@ -305,6 +305,11 @@ bool ViewModel::IsMarkupProcessorEnabled() const
   return mModel->IsMarkupProcessorEnabled();
 }
 
+bool ViewModel::IsSpannedTextPlaced() const
+{
+  return mModel->IsSpannedTextPlaced();
+}
+
 const GlyphInfo* ViewModel::GetHyphens() const
 {
   return mModel->GetHyphens();
index 71ad8bb..0e0c64e 100644 (file)
@@ -267,6 +267,11 @@ public:
   bool IsMarkupProcessorEnabled() const override;
 
   /**
+   * @copydoc ModelInterface::IsSpannedTextPlaced()
+   */
+  bool IsSpannedTextPlaced() const override;
+
+  /**
   * @copydoc ModelInterface::GetHyphens()
   */
   const GlyphInfo* GetHyphens() const override;
index df37c17..4859597 100644 (file)
@@ -350,6 +350,15 @@ public:
   virtual bool IsMarkupProcessorEnabled() const = 0;
 
   /**
+   * @brief Retrieves whether the spanned-text is placed.
+   *
+   * By default is disabled.
+   *
+   * @return @e true if the spanned-text is placed, otherwise returns @e false.
+   */
+  virtual bool IsSpannedTextPlaced() const = 0;
+
+  /**
    * @brief Returns the hyphens glyph info.
    *
    * @return hyphens glyph info.
index d6a26ed..b1d4d02 100644 (file)
@@ -247,6 +247,11 @@ bool Model::IsMarkupProcessorEnabled() const
   return mVisualModel->IsMarkupProcessorEnabled();
 }
 
+bool Model::IsSpannedTextPlaced() const
+{
+  return mLogicalModel->mSpannedTextPlaced;
+}
+
 const GlyphInfo* Model::GetHyphens() const
 {
   return mVisualModel->mHyphen.glyph.Begin();
index 0e224e5..945d5fc 100644 (file)
@@ -265,6 +265,11 @@ public:
   bool IsMarkupProcessorEnabled() const override;
 
   /**
+   * @copydoc ModelInterface::IsSpannedTextPlaced()
+   */
+  bool IsSpannedTextPlaced() const override;
+
+  /**
   * @copydoc ModelInterface::GetHyphens()
   */
   const GlyphInfo* GetHyphens() const override;
index 14e1ce3..ed778f4 100644 (file)
@@ -565,12 +565,12 @@ void TextVisual::UpdateRenderer()
 
       const bool outlineEnabled             = (mController->GetTextModel()->GetOutlineWidth() > Math::MACHINE_EPSILON_1);
       const bool backgroundEnabled          = mController->GetTextModel()->IsBackgroundEnabled();
-      const bool markupProcessorEnabled     = mController->IsMarkupProcessorEnabled();
-      const bool markupUnderlineEnabled     = markupProcessorEnabled && mController->GetTextModel()->IsMarkupUnderlineSet();
-      const bool markupStrikethroughEnabled = markupProcessorEnabled && mController->GetTextModel()->IsMarkupStrikethroughSet();
+      const bool markupOrSpannedText        = mController->IsMarkupProcessorEnabled() || mController->GetTextModel()->IsSpannedTextPlaced();
+      const bool markupUnderlineEnabled     = markupOrSpannedText && mController->GetTextModel()->IsMarkupUnderlineSet();
+      const bool markupStrikethroughEnabled = markupOrSpannedText && mController->GetTextModel()->IsMarkupStrikethroughSet();
       const bool underlineEnabled           = mController->GetTextModel()->IsUnderlineEnabled() || markupUnderlineEnabled;
       const bool strikethroughEnabled       = mController->GetTextModel()->IsStrikethroughEnabled() || markupStrikethroughEnabled;
-      const bool styleEnabled               = (shadowEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled);
+      const bool styleEnabled               = (shadowEnabled || outlineEnabled || backgroundEnabled || markupOrSpannedText);
       const bool isOverlayStyle             = underlineEnabled || strikethroughEnabled;
 
       AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);