Fix GetTextBoundingRectangle size issue
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / controller / text-controller.cpp
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};
 }