}
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
{