modified GetTextExtent for bidi(JIRA N_SE-25947)
authorSungyeon Woo <s.woo@samsung.com>
Tue, 26 Mar 2013 01:52:33 +0000 (10:52 +0900)
committerSungyeon Woo <s.woo@samsung.com>
Tue, 26 Mar 2013 02:12:17 +0000 (11:12 +0900)
Change-Id: Ifa506e7e33ac0ed3cfe55c279f0dbe6b1c70d282
Signed-off-by: Sungyeon Woo <s.woo@samsung.com>
src/graphics/FGrp_Font.cpp
src/graphics/util/FGrp_UtilTemplate.h [changed mode: 0755->0644]

index c6ece5e..c5ea689 100644 (file)
@@ -1136,101 +1136,40 @@ _Font::GetTextExtent(int width, const _Util::String& text, bool outline, int& co
                }
                else if (determinedCount > 0 && right - left > 0)
                {
-                       _TextBidiPropertyWithReorder determinedBidiProperty(text.pStart, determinedCount);
+                       int expectedValue = width * text.length / (right - left);
+                       int tolerance = _Util::Abs(expectedValue - determinedCount);
+                       tolerance = (tolerance == 0) ? 2 : tolerance;
 
-                       GapList determinedGapList;
+                       int tempCount = expectedValue <= determinedCount ? determinedCount + tolerance : determinedCount + (tolerance * 2);
+                       tempCount = tempCount > text.length ? text.length : tempCount;
 
-                       result r = this->__GetTextExtentList(determinedBidiProperty, determinedGapList);
+                       tempCount++;
 
-                       if (r != E_SUCCESS)
+                       while (right - left > width)
                        {
-                               return r;
-                       }
+                               _TextBidiPropertyWithReorder determinedBidiProperty(text.pStart, --tempCount);
 
-                       left = 0;
-                       right = 0;
+                               GapList determinedGapList;
 
-                       for (GapList::Iterator i = determinedGapList.Begin(); i != determinedGapList.End(); ++i)
-                       {
-                               left = (i->first < left) ? i->first : left;
-                               right = (i->second > right) ? i->second : right;
-                       }
-
-                       pcDim.SetSize(right - left, __fontAttrib.size.ToInt());
-                       count = determinedCount;
+                               result r = this->__GetTextExtentList(determinedBidiProperty, determinedGapList);
 
-// for arabic collation element
-                       if (text.pStart + count != null)
-                       {
-                               if (count > 0 && text.pStart + count != null && _TextBidiUtil::IsCollationElement(*(text.pStart + (count - 1)), *(text.pStart + (count - 1) + 1)))
+                               if (r != E_SUCCESS)
                                {
-                                       //count - 1 < width
-                                       _TextBidiPropertyWithReorder tempBidiProperty1(text.pStart, count - 1);
-
-                                       GapList tempGapList1;
-
-                                       result r = this->__GetTextExtentList(tempBidiProperty1, tempGapList1);
-
-                                       if (r != E_SUCCESS)
-                                       {
-                                               return r;
-                                       }
-
-                                       left = 0;
-                                       right = 0;
-
-                                       for (GapList::Iterator i = tempGapList1.Begin(); i != tempGapList1.End(); ++i)
-                                       {
-                                               left = (i->first < left) ? i->first : left;
-                                               right = (i->second > right) ? i->second : right;
-                                       }
-
-                                       int temp1Width = right - left;
-
-                                       //count + 1 < width
-                                       _TextBidiPropertyWithReorder tempBidiProperty2(text.pStart, count + 1);
-
-                                       GapList tempGapList2;
-
-                                       r = this->__GetTextExtentList(tempBidiProperty2, tempGapList2);
-
-                                       if (r != E_SUCCESS)
-                                       {
-                                               return r;
-                                       }
-
-                                       left = 0;
-                                       right = 0;
-
-                                       for (GapList::Iterator i = tempGapList2.Begin(); i != tempGapList2.End(); ++i)
-                                       {
-                                               left = (i->first < left) ? i->first : left;
-                                               right = (i->second > right) ? i->second : right;
-                                       }
+                                       return r;
+                               }
 
-                                       int temp2Width = right - left;
+                               left = 0;
+                               right = 0;
 
-                                       if (temp2Width < width)
-                                       {
-                                               if (temp2Width < temp1Width)
-                                               {
-                                                       pcDim.SetSize(temp1Width, __fontAttrib.size.ToInt());
-                                                       count--;
-                                               }
-                                               else
-                                               {
-                                                       pcDim.SetSize(temp2Width, __fontAttrib.size.ToInt());
-                                                       count++;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               pcDim.SetSize(temp1Width, __fontAttrib.size.ToInt());
-                                               count--;
-                                       }
+                               for (GapList::Iterator i = determinedGapList.Begin(); i != determinedGapList.End(); ++i)
+                               {
+                                       left = (i->first < left) ? i->first : left;
+                                       right = (i->second > right) ? i->second : right;
                                }
                        }
-/////
+
+                       pcDim.SetSize(right - left, __fontAttrib.size.ToInt());
+                       count = tempCount;
                }
                else
                {
old mode 100755 (executable)
new mode 100644 (file)
index b74a783..beb7442
@@ -37,6 +37,13 @@ namespace _Util
 
 template<typename T>
 inline T
+Abs(const T& t)
+{
+       return (t >= 0) ? t : -t;
+}
+
+template<typename T>
+inline T
 Min(T a, T b)
 {
        return (a < b) ? a : b;