* truncate_middle() could eat the whole string if it was as large as the
ellipsis. This was visible in missing window titles for short names like "bin". git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26960 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1324,7 +1324,8 @@ truncate_middle(const char* source, char* dest, uint32 numChars,
|
||||
{
|
||||
// find visual center
|
||||
|
||||
ellipsisWidth /= size; // test if this is as accurate as escapementArray * size
|
||||
ellipsisWidth /= size;
|
||||
// test if this is as accurate as escapementArray * size
|
||||
width /= size;
|
||||
|
||||
float halfWidth = (width - ellipsisWidth) / 2.0;
|
||||
@@ -1345,6 +1346,16 @@ truncate_middle(const char* source, char* dest, uint32 numChars,
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if the whole string fits in
|
||||
|
||||
float stringWidth = leftWidth;
|
||||
uint32 i = left;
|
||||
for (; i < numChars && stringWidth < width; i++) {
|
||||
stringWidth += escapementArray[i];
|
||||
}
|
||||
if (stringWidth < width)
|
||||
return false;
|
||||
|
||||
// coming from right...
|
||||
|
||||
for (right = numChars; right-- > left; ) {
|
||||
@@ -1426,13 +1437,13 @@ truncate_middle(const char* source, char* dest, uint32 numChars,
|
||||
}
|
||||
|
||||
|
||||
// ToDo: put into BPrivate namespace
|
||||
// TODO: put into BPrivate namespace
|
||||
void
|
||||
truncate_string(const char* string, uint32 mode, float width,
|
||||
char* result, const float* escapementArray, float fontSize,
|
||||
float ellipsisWidth, int32 length, int32 numChars)
|
||||
{
|
||||
// ToDo: that's actually not correct: the string could be smaller than ellipsisWidth
|
||||
// TODO: that's actually not correct: the string could be smaller than ellipsisWidth
|
||||
if (string == NULL /*|| width < ellipsisWidth*/) {
|
||||
// we don't have room for a single glyph
|
||||
strcpy(result, "");
|
||||
|
||||
Reference in New Issue
Block a user