From: sarajammal Date: Sun, 27 Nov 2022 16:00:26 +0000 (+0300) Subject: Add GetTextBoundingRectangle API for Text Controllers X-Git-Tag: dali_2.2.9~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F95%2F284795%2F8;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Add GetTextBoundingRectangle API for Text Controllers 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 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index fac21a0..17d7d30 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -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 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 63eac09..d6ac646 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -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 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 41783dc..1aecd89 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -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 diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp index 41d0c34..eeef11f 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp @@ -95,6 +95,11 @@ Vector 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(); diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index 92c2e59..9aab35f 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -543,6 +543,16 @@ DALI_TOOLKIT_API Vector GetTextSize(TextEditor textEditor, const uint32 DALI_TOOLKIT_API Vector 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. diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp index 345bb12..2105756 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp @@ -85,6 +85,11 @@ Vector 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(); diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index c81210a..a061819 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -413,6 +413,16 @@ DALI_TOOLKIT_API Vector GetTextSize(TextField textField, const uint32_t DALI_TOOLKIT_API Vector 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. diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp index 5e6bc02..d42e274 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp @@ -45,6 +45,11 @@ Vector 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 diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index 326d8d0..a96092f 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -230,6 +230,16 @@ DALI_TOOLKIT_API Vector GetTextSize(TextLabel textLabel, const uint32_t DALI_TOOLKIT_API Vector 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 diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index ea5f43c..2ceb454 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -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); diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 5591439..117a09b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -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 diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index e7a8f4b..96edfe4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -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); diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index 43bde7a..fe5056e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -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 diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index fb41c56..4f4503b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -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); diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index 6e34534..b564958 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -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