From c58c49ba4b68d3e398defe6da67a3f5393cd8ee2 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Fri, 16 Sep 2022 14:54:18 +0900 Subject: [PATCH] Fix GetTextBoundingRectangle size issue TextGeometry calculates the size and position of the actual text with glyphAdvance. This means that sometimes the x position will be negative, or the text's line width may be greater than the control's width. While this is an accurate value, it is not suitable for calculating the minimum bounding rect of text. Because the text appears to be outside the control. This patch adjusts the return value of GetTextBoundingRectangle() so that it does not exceed the bounds of the text control. Change-Id: Ie80ac1a8b5cec5f8c21013744645254381c78fb6 Signed-off-by: Bowon Ryu --- .../utc-Dali-Accessibility-Text.cpp | 51 +++++----------------- .../internal/text/controller/text-controller.cpp | 19 ++++++-- 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Text.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Text.cpp index 073138a..4389b90 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Text.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Text.cpp @@ -234,19 +234,10 @@ int utcDaliAccessibilityTextEditorGetRangeExtents(void) auto characterCount = x->GetCharacterCount(); rangeExtents = x->GetRangeExtents( 0, characterCount, Dali::Accessibility::CoordinateType::WINDOW ); - Vector positionList = Toolkit::DevelTextEditor::GetTextPosition(editor, 0, characterCount); - Vector sizeList = Toolkit::DevelTextEditor::GetTextSize(editor, 0, characterCount); - - DALI_TEST_EQUALS(positionList.Size() == sizeList.Size(), true, TEST_LOCATION); - - unsigned int sizeListSize = sizeList.Size(); - for(unsigned int i = 0; i < sizeListSize; i++) - { - DALI_TEST_EQUALS((int)positionList[i].x >= rangeExtents.x, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)positionList[i].y >= rangeExtents.y, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)sizeList[i].x <= rangeExtents.width, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)sizeList[i].y <= rangeExtents.height, true, TEST_LOCATION); - } + DALI_TEST_EQUALS((int)rangeExtents.x >= 0, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.y >= 0, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.width <= 200, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.height <= 200, true, TEST_LOCATION); } END_TEST; @@ -478,19 +469,10 @@ int utcDaliAccessibilityTextFieldGetRangeExtents(void) auto characterCount = x->GetCharacterCount(); rangeExtents = x->GetRangeExtents( 0, characterCount, Dali::Accessibility::CoordinateType::WINDOW ); - Vector positionList = Toolkit::DevelTextField::GetTextPosition(field, 0, characterCount); - Vector sizeList = Toolkit::DevelTextField::GetTextSize(field, 0, characterCount); - - DALI_TEST_EQUALS(positionList.Size() == sizeList.Size(), true, TEST_LOCATION); - - unsigned int sizeListSize = sizeList.Size(); - for(unsigned int i = 0; i < sizeListSize; i++) - { - DALI_TEST_EQUALS((int)positionList[i].x >= rangeExtents.x, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)positionList[i].y >= rangeExtents.y, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)sizeList[i].x <= rangeExtents.width, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)sizeList[i].y <= rangeExtents.height, true, TEST_LOCATION); - } + DALI_TEST_EQUALS((int)rangeExtents.x >= 0, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.y >= 0, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.width <= 200, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.height <= 200, true, TEST_LOCATION); } END_TEST; @@ -663,19 +645,10 @@ int utcDaliAccessibilityTextLabelGetRangeExtents(void) auto characterCount = x->GetCharacterCount(); rangeExtents = x->GetRangeExtents( 0, characterCount, Dali::Accessibility::CoordinateType::WINDOW ); - Vector positionList = Toolkit::DevelTextLabel::GetTextPosition(label, 0, characterCount); - Vector sizeList = Toolkit::DevelTextLabel::GetTextSize(label, 0, characterCount); - - DALI_TEST_EQUALS(positionList.Size() == sizeList.Size(), true, TEST_LOCATION); - - unsigned int sizeListSize = sizeList.Size(); - for(unsigned int i = 0; i < sizeListSize; i++) - { - DALI_TEST_EQUALS((int)positionList[i].x >= rangeExtents.x, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)positionList[i].y >= rangeExtents.y, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)sizeList[i].x <= rangeExtents.width, true, TEST_LOCATION); - DALI_TEST_EQUALS((int)sizeList[i].y <= rangeExtents.height, true, TEST_LOCATION); - } + DALI_TEST_EQUALS((int)rangeExtents.x >= 0, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.y >= 0, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.width <= 200, true, TEST_LOCATION); + DALI_TEST_EQUALS((int)rangeExtents.height <= 200, true, TEST_LOCATION); } END_TEST; diff --git a/dali-toolkit/internal/text/controller/text-controller.cpp b/dali-toolkit/internal/text/controller/text-controller.cpp index 5f775f7..b3b55b1 100644 --- a/dali-toolkit/internal/text/controller/text-controller.cpp +++ b/dali-toolkit/internal/text/controller/text-controller.cpp @@ -1428,10 +1428,11 @@ Rect<> Controller::GetTextBoundingRectangle(CharacterIndex startIndex, Character return {0, 0, 0, 0}; } - auto minX = positionList[0].x; - auto minY = positionList[0].y; - auto maxRight = positionList[0].x + sizeList[0].x; - auto maxBottom = positionList[0].y + sizeList[0].y; + auto controlWidth = mImpl->mModel->mVisualModel->mControlSize.width; + auto minX = positionList[0].x; + auto minY = positionList[0].y; + auto maxRight = positionList[0].x + sizeList[0].x; + auto maxBottom = positionList[0].y + sizeList[0].y; for(unsigned int i = 1; i < sizeList.Size(); i++) { @@ -1441,6 +1442,16 @@ Rect<> Controller::GetTextBoundingRectangle(CharacterIndex startIndex, Character maxBottom = std::max(maxBottom, positionList[i].y + sizeList[i].y); } + if(minX < 0.0f) + { + minX = 0.0f; + } + + if(maxRight > controlWidth) + { + maxRight = controlWidth; + } + return {minX, minY, maxRight - minX, maxBottom - minY}; } -- 2.7.4