Add GetTextBoundingRectangle API for Text Controllers 95/284795/8
authorsarajammal <s.al-jammal@partner.samsung.com>
Sun, 27 Nov 2022 16:00:26 +0000 (19:00 +0300)
committerSara AlJammal <s.al-jammal@partner.samsung.com>
Tue, 27 Dec 2022 09:21:03 +0000 (09:21 +0000)
API was already implemented, this patch adds it n Text Label, Field and Editor.
To be able to add it on NUI too.

Change-Id: I98120cc70c805a2bb1fee7abaf6625cc3ec42d65

15 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
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp
dali-toolkit/devel-api/controls/text-controls/text-field-devel.h
dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
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

index fac21a0..17d7d30 100644 (file)
@@ -6396,3 +6396,37 @@ int utcDaliTextEditorPanGesturePropagation(void)
 
   END_TEST;
 }
+
+int utcDaliTextEditorGetTextBoundingRectangle(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextEditorGeometryEllipsisMiddle");
+
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK(editor);
+
+  application.GetScene().Add(editor);
+
+  editor.SetProperty(TextEditor::Property::POINT_SIZE, 7.f);
+  editor.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
+  editor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  editor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  editor.SetProperty(TextEditor::Property::TEXT, "Hello this is the Text Bounding Rectangle TC");
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  unsigned int startIndex    = 0;
+  unsigned int endIndex      = 15;
+
+  Rect<> textBoundingRectangle = DevelTextEditor::GetTextBoundingRectangle(editor, startIndex, endIndex);
+  Rect<> expectedTextBoundingRectangle = {0, 0, 100, 50};
+
+  TestTextGeometryUtils::CheckRectGeometryResult(textBoundingRectangle, expectedTextBoundingRectangle);
+
+  END_TEST;
+}
\ No newline at end of file
index 63eac09..d6ac646 100644 (file)
@@ -5786,3 +5786,37 @@ int utcDaliTextFieldPanGesturePropagation(void)
 
   END_TEST;
 }
+
+int utcDaliTextFieldGetTextBoundingRectangle(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextFieldGeometryEllipsisMiddle");
+
+  TextField field = TextField::New();
+  DALI_TEST_CHECK(field);
+
+  application.GetScene().Add(field);
+
+  field.SetProperty(TextField::Property::POINT_SIZE, 7.f);
+  field.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
+  field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  field.SetProperty(TextField::Property::TEXT, "Hello this is the Text Bounding Rectangle TC");
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  unsigned int startIndex    = 0;
+  unsigned int endIndex      = 15;
+
+  Rect<> textBoundingRectangle = DevelTextField::GetTextBoundingRectangle(field, startIndex, endIndex);
+  Rect<> expectedTextBoundingRectangle = {0, 0, 100, 25};
+
+  TestTextGeometryUtils::CheckRectGeometryResult(textBoundingRectangle, expectedTextBoundingRectangle);
+
+  END_TEST;
+}
\ No newline at end of file
index 41783dc..1aecd89 100644 (file)
@@ -3079,4 +3079,38 @@ int UtcDaliToolkitTextlabelParagraphTag(void)
   application.Render();
 
   END_TEST;
+}
+
+int utcDaliTextLabelGetTextBoundingRectangle(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" utcDaliTextLabelGeometryEllipsisMiddle");
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  application.GetScene().Add(label);
+
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 7.f);
+  label.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
+  label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  label.SetProperty(TextLabel::Property::TEXT, "Hello this is the Text Bounding Rectangle TC");
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  unsigned int startIndex    = 0;
+  unsigned int endIndex      = 15;
+
+  Rect<> textBoundingRectangle = DevelTextLabel::GetTextBoundingRectangle(label, startIndex, endIndex);
+  Rect<> expectedTextBoundingRectangle = {0, 0, 100, 25};
+
+  TestTextGeometryUtils::CheckRectGeometryResult(textBoundingRectangle, expectedTextBoundingRectangle);
+
+  END_TEST;
 }
\ No newline at end of file
index 41d0c34..eeef11f 100644 (file)
@@ -95,6 +95,11 @@ Vector<Vector2> GetTextPosition(TextEditor textEditor, const uint32_t startIndex
   return GetImpl(textEditor).GetTextPosition(startIndex, endIndex);
 }
 
+Rect<> GetTextBoundingRectangle(TextEditor textEditor, uint32_t startIndex, uint32_t endIndex)
+{
+  return GetImpl(textEditor).GetTextBoundingRectangle(startIndex, endIndex);
+}
+
 string CopyText(TextEditor textEditor)
 {
   return GetImpl(textEditor).CopyText();
index 92c2e59..9aab35f 100644 (file)
@@ -543,6 +543,16 @@ DALI_TOOLKIT_API Vector<Vector2> GetTextSize(TextEditor textEditor, const uint32
 DALI_TOOLKIT_API Vector<Vector2> GetTextPosition(TextEditor textEditor, const uint32_t startIndex, const uint32_t endIndex);
 
 /**
+ * @brief Gets the bounding box of a specific text range.
+ *
+ * @param[in] textEditor The instance of textEditor.
+ * @param[in] startIndex start index of the text requested to get bounding box to.
+ * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+ * @return bounding box of the requested text.
+ */
+DALI_TOOLKIT_API Rect<> GetTextBoundingRectangle(TextEditor textEditor, uint32_t startIndex, uint32_t endIndex);
+
+/**
  * @brief Copy and return the selected text of TextEditor.
  *
  * @param[in] textEditor The instance of TextEditor.
index 345bb12..2105756 100644 (file)
@@ -85,6 +85,11 @@ Vector<Vector2> GetTextPosition(TextField textField, const uint32_t startIndex,
   return GetImpl(textField).GetTextPosition(startIndex, endIndex);
 }
 
+Rect<> GetTextBoundingRectangle(TextField textField, uint32_t startIndex, uint32_t endIndex)
+{
+  return GetImpl(textField).GetTextBoundingRectangle(startIndex, endIndex);
+}
+
 string CopyText(TextField textField)
 {
   return GetImpl(textField).CopyText();
index c81210a..a061819 100644 (file)
@@ -413,6 +413,16 @@ DALI_TOOLKIT_API Vector<Vector2> GetTextSize(TextField textField, const uint32_t
 DALI_TOOLKIT_API Vector<Vector2> GetTextPosition(TextField textField, const uint32_t startIndex, const uint32_t endIndex);
 
 /**
+ * @brief Gets the bounding box of a specific text range.
+ *
+ * @param[in] textField The instance of textField.
+ * @param[in] startIndex start index of the text requested to get bounding box to.
+ * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+ * @return bounding box of the requested text.
+ */
+DALI_TOOLKIT_API Rect<> GetTextBoundingRectangle(TextField textField, uint32_t startIndex, uint32_t endIndex);
+
+/**
  * @brief Select the whole text of TextField.
  *
  * @param[in] textField The instance of TextField.
index 5e6bc02..d42e274 100644 (file)
@@ -45,6 +45,11 @@ Vector<Vector2> GetTextPosition(TextLabel textLabel, const uint32_t startIndex,
   return GetImpl(textLabel).GetTextPosition(startIndex, endIndex);
 }
 
+Rect<> GetTextBoundingRectangle(TextLabel textLabel, uint32_t startIndex, uint32_t endIndex)
+{
+  return GetImpl(textLabel).GetTextBoundingRectangle(startIndex, endIndex);
+}
+
 } // namespace DevelTextLabel
 
 } // namespace Toolkit
index 326d8d0..a96092f 100644 (file)
@@ -230,6 +230,16 @@ DALI_TOOLKIT_API Vector<Vector2> GetTextSize(TextLabel textLabel, const uint32_t
 DALI_TOOLKIT_API Vector<Vector2> GetTextPosition(TextLabel textLabel, const uint32_t startIndex, const uint32_t endIndex);
 
 /**
+ * @brief Gets the bounding box of a specific text range.
+ *
+ * @param[in] textLabel The instance of TextLabel.
+ * @param[in] startIndex start index of the text requested to get bounding box to.
+ * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+ * @return bounding box of the requested text.
+ */
+DALI_TOOLKIT_API Rect<> GetTextBoundingRectangle(TextLabel textLabel, uint32_t startIndex, uint32_t endIndex);
+
+/**
  * @brief Anchor clicked signal type.
  *
  * @note Signal
index ea5f43c..2ceb454 100644 (file)
@@ -379,6 +379,11 @@ int TextEditor::GetCharacterIndexAtPosition(float visualX, float visualY) const
   return mController->GetCharacterIndexAtPosition(visualX, visualY);
 }
 
+Rect<> TextEditor::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
+{
+  return mController->GetTextBoundingRectangle(startIndex, endIndex);
+}
+
 void TextEditor::SetSpannedText(const Text::Spanned& spannedText)
 {
   mController->SetSpannedText(spannedText);
index 5591439..117a09b 100644 (file)
@@ -387,6 +387,15 @@ public:
   int GetCharacterIndexAtPosition(float visualX, float visualY) const;
 
   /**
+   * @brief Gets the bounding box of a specific text range.
+   *
+   * @param[in] startIndex start index of the text requested to get bounding box to.
+   * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+   * @return bounding box of the requested text.
+   */
+  Rect<> GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) 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
index e7a8f4b..96edfe4 100644 (file)
@@ -1220,6 +1220,11 @@ int TextField::GetCharacterIndexAtPosition(float visualX, float visualY) const
   return mController->GetCharacterIndexAtPosition(visualX, visualY);
 }
 
+Rect<> TextField::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
+{
+  return mController->GetTextBoundingRectangle(startIndex, endIndex);
+}
+
 void TextField::SetSpannedText(const Text::Spanned& spannedText)
 {
   mController->SetSpannedText(spannedText);
index 43bde7a..fe5056e 100644 (file)
@@ -396,6 +396,15 @@ public:
   int GetCharacterIndexAtPosition(float visualX, float visualY) const;
 
   /**
+   * @brief Gets the bounding box of a specific text range.
+   *
+   * @param[in] startIndex start index of the text requested to get bounding box to.
+   * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+   * @return bounding box of the requested text.
+   */
+  Rect<> GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) 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
index fb41c56..4f4503b 100644 (file)
@@ -1251,6 +1251,11 @@ int TextLabel::GetCharacterIndexAtPosition(float visualX, float visualY) const
   return mController->GetCharacterIndexAtPosition(visualX, visualY);
 }
 
+Rect<> TextLabel::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
+{
+  return mController->GetTextBoundingRectangle(startIndex, endIndex);
+}
+
 void TextLabel::SetSpannedText(const Text::Spanned& spannedText)
 {
   mController->SetSpannedText(spannedText);
index 6e34534..b564958 100644 (file)
@@ -154,6 +154,15 @@ public:
   int GetCharacterIndexAtPosition(float visualX, float visualY) const;
 
   /**
+   * @brief Gets the bounding box of a specific text range.
+   *
+   * @param[in] startIndex start index of the text requested to get bounding box to.
+   * @param[in] endIndex end index(included) of the text requested to get bounding box to.
+   * @return bounding box of the requested text.
+   */
+  Rect<> GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) 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