Fix GetTextBoundingRectangle size issue 70/281370/2
authorBowon Ryu <bowon.ryu@samsung.com>
Fri, 16 Sep 2022 05:54:18 +0000 (14:54 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Fri, 16 Sep 2022 08:51:33 +0000 (17:51 +0900)
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 <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Text.cpp
dali-toolkit/internal/text/controller/text-controller.cpp

index 073138a..4389b90 100644 (file)
@@ -234,19 +234,10 @@ int utcDaliAccessibilityTextEditorGetRangeExtents(void)
     auto characterCount = x->GetCharacterCount();
     rangeExtents        = x->GetRangeExtents( 0, characterCount, Dali::Accessibility::CoordinateType::WINDOW );
 
-    Vector<Vector2> positionList = Toolkit::DevelTextEditor::GetTextPosition(editor, 0, characterCount);
-    Vector<Vector2> 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<Vector2> positionList = Toolkit::DevelTextField::GetTextPosition(field, 0, characterCount);
-    Vector<Vector2> 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<Vector2> positionList = Toolkit::DevelTextLabel::GetTextPosition(label, 0, characterCount);
-    Vector<Vector2> 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;
index 5f775f7..b3b55b1 100644 (file)
@@ -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};
 }