Minor cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17538 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -85,30 +85,30 @@ _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);
|
||||||
|
|
||||||
char *text = NULL;
|
char *text = NULL;
|
||||||
int32 numChars = 0;
|
int32 numChars = 0;
|
||||||
int32 textLen = 0;
|
int32 textLen = 0;
|
||||||
|
|
||||||
const float fontSize = inStyle->Size();
|
const float fontSize = inStyle->Size();
|
||||||
float stringWidth = 0;
|
float stringWidth = 0;
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
for (int32 charLen = 0, currentOffset = fromOffset;
|
for (int32 charLen = 0, currentOffset = fromOffset;
|
||||||
currentOffset < fromOffset + length;
|
currentOffset < fromOffset + length;
|
||||||
currentOffset += charLen) {
|
currentOffset += charLen) {
|
||||||
|
|
||||||
charLen = UTF8NextCharLen(inText + currentOffset);
|
charLen = UTF8NextCharLen(inText + currentOffset);
|
||||||
|
|
||||||
// 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
|
||||||
const uint32 value = CharToCode(inText + currentOffset, charLen);
|
const 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
|
||||||
@@ -125,7 +125,7 @@ _BWidthBuffer_::StringWidth(const char *inText, int32 fromOffset, int32 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()
|
||||||
@@ -172,11 +172,12 @@ _BWidthBuffer_::FindTable(const BFont *inStyle, int32 *outIndex)
|
|||||||
for (int32 i = 0; i < fItemCount; i++) {
|
for (int32 i = 0; i < fItemCount; i++) {
|
||||||
|
|
||||||
#if USE_DANO_WIDTHBUFFER
|
#if USE_DANO_WIDTHBUFFER
|
||||||
if (*inStyle == fBuffer[i].font) {
|
if (*inStyle == fBuffer[i].font)
|
||||||
#else
|
#else
|
||||||
if (fontSize == fBuffer[i].fontSize
|
if (fontSize == fBuffer[i].fontSize
|
||||||
&& fontCode == fBuffer[i].fontCode) {
|
&& fontCode == fBuffer[i].fontCode)
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
tableIndex = i;
|
tableIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -283,24 +284,24 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
|
|||||||
{
|
{
|
||||||
float *escapements = new float[numChars];
|
float *escapements = new float[numChars];
|
||||||
inStyle->GetEscapements(inText, numChars, escapements);
|
inStyle->GetEscapements(inText, numChars, escapements);
|
||||||
|
|
||||||
_width_table_ &table = fBuffer[tableIndex];
|
_width_table_ &table = fBuffer[tableIndex];
|
||||||
hashed_escapement *widths = static_cast<hashed_escapement *>(table.widths);
|
hashed_escapement *widths = static_cast<hashed_escapement *>(table.widths);
|
||||||
|
|
||||||
int32 offset = 0;
|
int32 offset = 0;
|
||||||
int32 charCount = 0;
|
int32 charCount = 0;
|
||||||
|
|
||||||
// Insert the escapements into the hash table
|
// Insert the escapements into the hash table
|
||||||
do {
|
do {
|
||||||
const int32 charLen = UTF8NextCharLen(inText + offset);
|
const int32 charLen = UTF8NextCharLen(inText + offset);
|
||||||
if (charLen == 0)
|
if (charLen == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const uint32 value = CharToCode(inText + offset, charLen);
|
const uint32 value = CharToCode(inText + offset, charLen);
|
||||||
|
|
||||||
uint32 hashed = Hash(value) & (table.tableCount - 1);
|
uint32 hashed = Hash(value) & (table.tableCount - 1);
|
||||||
uint32 found = widths[hashed].code;
|
uint32 found = widths[hashed].code;
|
||||||
|
|
||||||
// Check if the value is already in the table
|
// Check if the value is already in the table
|
||||||
if (found != value) {
|
if (found != value) {
|
||||||
while ((found = widths[hashed].code) != kInvalidCode) {
|
while ((found = widths[hashed].code) != kInvalidCode) {
|
||||||
@@ -309,13 +310,13 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
|
|||||||
if (++hashed >= (uint32)table.tableCount)
|
if (++hashed >= (uint32)table.tableCount)
|
||||||
hashed = 0;
|
hashed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found == kInvalidCode) {
|
if (found == kInvalidCode) {
|
||||||
// The value is not in the table. Add it.
|
// The value is not in the table. Add it.
|
||||||
widths[hashed].code = value;
|
widths[hashed].code = value;
|
||||||
widths[hashed].escapement = escapements[charCount];
|
widths[hashed].escapement = escapements[charCount];
|
||||||
table.hashCount++;
|
table.hashCount++;
|
||||||
|
|
||||||
// We always keep some free space in the hash table
|
// We always keep some free space in the hash table
|
||||||
// TODO: Not sure how much space, currently we double
|
// TODO: Not sure how much space, currently we double
|
||||||
// the current size when hashCount is at least 2/3 of
|
// the current size when hashCount is at least 2/3 of
|
||||||
@@ -323,7 +324,7 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
|
|||||||
if (table.tableCount * 2 / 3 <= table.hashCount) {
|
if (table.tableCount * 2 / 3 <= table.hashCount) {
|
||||||
table.hashCount = 0;
|
table.hashCount = 0;
|
||||||
const int32 newSize = table.tableCount * 2;
|
const int32 newSize = table.tableCount * 2;
|
||||||
|
|
||||||
// Create and initialize a new hash table
|
// Create and initialize a new hash table
|
||||||
hashed_escapement *newWidths = new hashed_escapement[newSize];
|
hashed_escapement *newWidths = new hashed_escapement[newSize];
|
||||||
|
|
||||||
@@ -341,7 +342,7 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
table.tableCount = newSize;
|
table.tableCount = newSize;
|
||||||
|
|
||||||
// Delete the old table, and put the new pointer into the _width_table_
|
// Delete the old table, and put the new pointer into the _width_table_
|
||||||
delete[] widths;
|
delete[] widths;
|
||||||
widths = newWidths;
|
widths = newWidths;
|
||||||
@@ -351,7 +352,7 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
|
|||||||
charCount++;
|
charCount++;
|
||||||
offset += charLen;
|
offset += charLen;
|
||||||
} while (offset < textLen);
|
} while (offset < textLen);
|
||||||
|
|
||||||
// Calculate the width of the string
|
// Calculate the width of the string
|
||||||
float width = 0;
|
float width = 0;
|
||||||
for (int32 x = 0; x < numChars; x++)
|
for (int32 x = 0; x < numChars; x++)
|
||||||
|
|||||||
Reference in New Issue
Block a user