Fixed a bad bug in WidthBuffer, which would make BTextView behave in a weird way.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9404 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3582,7 +3582,7 @@ BTextView::StyledWidth(int32 fromOffset, int32 length, float *outAscent,
|
|||||||
// Use _BWidthBuffer_ if possible
|
// Use _BWidthBuffer_ if possible
|
||||||
if (sWidths != NULL) {
|
if (sWidths != NULL) {
|
||||||
LockWidthBuffer();
|
LockWidthBuffer();
|
||||||
result += sWidths->StringWidth(fText->Text(), fromOffset, numChars, font);
|
result += sWidths->StringWidth(*fText, fromOffset, numChars, font);
|
||||||
UnlockWidthBuffer();
|
UnlockWidthBuffer();
|
||||||
} else
|
} else
|
||||||
result += font->StringWidth(fText->Text() + fromOffset, numChars);
|
result += font->StringWidth(fText->Text() + fromOffset, numChars);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003 Stefano Ceccherini
|
* Copyright (c) 2003-2004 Haiku, Inc.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -18,8 +18,12 @@
|
|||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
* DEALINGS IN THE SOFTWARE.
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* File: WidthBuffer.cpp
|
||||||
|
* Author: Stefano Ceccherini ([email protected])
|
||||||
|
* Description: Caches string widths in a hash table, to avoid a trip to
|
||||||
|
* the app server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
|
|
||||||
@@ -29,7 +33,6 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
const uint32 kTableCount = 128;
|
const uint32 kTableCount = 128;
|
||||||
|
|
||||||
struct hashed_escapement
|
struct hashed_escapement
|
||||||
@@ -90,7 +93,7 @@ _BWidthBuffer_::StringWidth(const char *inText, int32 fromOffset, int32 length,
|
|||||||
{
|
{
|
||||||
if (inText == NULL)
|
if (inText == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
if (!FindTable(inStyle, &index))
|
if (!FindTable(inStyle, &index))
|
||||||
index = InsertTable(inStyle);
|
index = InsertTable(inStyle);
|
||||||
@@ -98,23 +101,26 @@ _BWidthBuffer_::StringWidth(const char *inText, int32 fromOffset, int32 length,
|
|||||||
char *text = NULL;
|
char *text = NULL;
|
||||||
int32 numChars = 0;
|
int32 numChars = 0;
|
||||||
int32 textLen = 0;
|
int32 textLen = 0;
|
||||||
float fontSize = inStyle->Size();
|
|
||||||
|
|
||||||
|
float fontSize = inStyle->Size();
|
||||||
float stringWidth = 0;
|
float stringWidth = 0;
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
do {
|
for (int32 charLen = 0, currentOffset = fromOffset;
|
||||||
int32 charLen = UTF8NextCharLen(inText + fromOffset);
|
currentOffset < fromOffset + length;
|
||||||
|
currentOffset += charLen) {
|
||||||
|
|
||||||
|
charLen = UTF8NextCharLen(inText + fromOffset);
|
||||||
// End of string, bail out
|
// End of string, bail out
|
||||||
if (charLen == 0)
|
if (charLen == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Some magic, to uniquely identify this charachter
|
// Some magic, to uniquely identify this charachter
|
||||||
uint32 value = CharToCode(inText + fromOffset, charLen);
|
uint32 value = CharToCode(inText + currentOffset, charLen);
|
||||||
|
|
||||||
float escapement;
|
float escapement;
|
||||||
if (GetEscapement(value, index, &escapement)) {
|
if (GetEscapement(value, index, &escapement)) {
|
||||||
// Well, we've got a match for this charachter
|
// Well, we've got a match for this charachter
|
||||||
stringWidth += escapement * fontSize;
|
stringWidth += escapement;
|
||||||
} else {
|
} else {
|
||||||
// Store this charachter into an array, which we'll
|
// Store this charachter into an array, which we'll
|
||||||
// pass to HashEscapements() later
|
// pass to HashEscapements() later
|
||||||
@@ -123,20 +129,19 @@ _BWidthBuffer_::StringWidth(const char *inText, int32 fromOffset, int32 length,
|
|||||||
numChars++;
|
numChars++;
|
||||||
text = (char *)realloc(text, textLen);
|
text = (char *)realloc(text, textLen);
|
||||||
for (int32 x = 0; x < charLen; x++)
|
for (int32 x = 0; x < charLen; x++)
|
||||||
text[offset + x] = inText[fromOffset + x];
|
text[offset + x] = inText[currentOffset + x];
|
||||||
}
|
}
|
||||||
fromOffset += charLen;
|
}
|
||||||
} while (fromOffset < length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text != NULL) {
|
if (text != NULL) {
|
||||||
// We've found some charachters which aren't yet in the hash table.
|
// We've found some charachters which aren't yet in the hash table.
|
||||||
// Get their width via HashEscapements()
|
// Get their width via HashEscapements()
|
||||||
stringWidth += HashEscapements(text, numChars, textLen, index, inStyle) * fontSize;
|
stringWidth += HashEscapements(text, numChars, textLen, index, inStyle);
|
||||||
free(text);
|
free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringWidth;
|
return stringWidth * fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user