Fixed truncate_middle(): could add ellipsis without any reason under some

circumstances.
Also, the first letter that is tested to be added to either side is taken
from the side with less letters now, instead of the one with the bigger
letter.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13552 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-07-08 01:41:38 +00:00
parent 66c912db47
commit 8ec0a618a1

View File

@ -1192,13 +1192,28 @@ truncate_middle(const char* source, char* dest, uint32 numChars,
strcpy(dest, "");
return true;
}
// see if the gap between left/right is smaller than the ellipsis
float totalWidth = rightWidth + leftWidth;
for (uint32 i = left; i < right; i++) {
totalWidth += escapementArray[i];
if (totalWidth > width)
break;
}
if (totalWidth <= width) {
// the whole string fits!
return false;
}
// The ellipsis now definitely fits, but let's
// see if we can add another character
float totalWidth = ellipsisWidth + rightWidth + leftWidth;
totalWidth = ellipsisWidth + rightWidth + leftWidth;
if (escapementArray[left] < escapementArray[right]) {
if (left > numChars - right) {
// try right letter first
if (escapementArray[right] + totalWidth <= width)
right--;