From 72d91f6d30609dc2c9a87e28ad020adfc92c8656 Mon Sep 17 00:00:00 2001 From: Sungyeon Woo Date: Tue, 26 Mar 2013 10:52:33 +0900 Subject: [PATCH] modified GetTextExtent for bidi(JIRA N_SE-25947) Change-Id: Ifa506e7e33ac0ed3cfe55c279f0dbe6b1c70d282 Signed-off-by: Sungyeon Woo --- src/graphics/FGrp_Font.cpp | 105 +++++++--------------------------- src/graphics/util/FGrp_UtilTemplate.h | 7 +++ 2 files changed, 29 insertions(+), 83 deletions(-) mode change 100755 => 100644 src/graphics/util/FGrp_UtilTemplate.h diff --git a/src/graphics/FGrp_Font.cpp b/src/graphics/FGrp_Font.cpp index c6ece5e..c5ea689 100644 --- a/src/graphics/FGrp_Font.cpp +++ b/src/graphics/FGrp_Font.cpp @@ -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 { diff --git a/src/graphics/util/FGrp_UtilTemplate.h b/src/graphics/util/FGrp_UtilTemplate.h old mode 100755 new mode 100644 index b74a783..beb7442 --- a/src/graphics/util/FGrp_UtilTemplate.h +++ b/src/graphics/util/FGrp_UtilTemplate.h @@ -37,6 +37,13 @@ namespace _Util template inline T +Abs(const T& t) +{ + return (t >= 0) ? t : -t; +} + +template +inline T Min(T a, T b) { return (a < b) ? a : b; -- 2.7.4