Fixed a crash when running beshare with our BTextView (thanks to Andrew Bachmann for reporting), though it's a bit hackish, added some printfs to TextView.cpp to help finding/fixing bugs, a small optimization to WidthBuffer. Should convert and commit WidthBuffer's tests to cppunit tests sooner or later.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6989 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
//#define USE_DANO_WIDTHBUFFER
|
||||||
|
|
||||||
const uint32 kTableCount = 128;
|
const uint32 kTableCount = 128;
|
||||||
|
|
||||||
struct hashed_escapement
|
struct hashed_escapement
|
||||||
@@ -171,10 +173,12 @@ _BWidthBuffer_::FindTable(const BFont *inStyle, int32 *outIndex)
|
|||||||
int32 tableIndex = -1;
|
int32 tableIndex = -1;
|
||||||
|
|
||||||
for (int32 i = 0; i < fItemCount; i++) {
|
for (int32 i = 0; i < fItemCount; i++) {
|
||||||
#if B_BEOS_VERSION_DANO
|
|
||||||
|
#ifdef USE_DANO_WIDTHBUFFER
|
||||||
if (*inStyle == fBuffer[i].font) {
|
if (*inStyle == fBuffer[i].font) {
|
||||||
#else
|
#else
|
||||||
if (fontSize == fBuffer[i].fontSize && fontCode == fBuffer[i].fontCode) {
|
if (fontSize == fBuffer[i].fontSize
|
||||||
|
&& fontCode == fBuffer[i].fontCode) {
|
||||||
#endif
|
#endif
|
||||||
tableIndex = i;
|
tableIndex = i;
|
||||||
break;
|
break;
|
||||||
@@ -196,12 +200,14 @@ _BWidthBuffer_::InsertTable(const BFont *font)
|
|||||||
{
|
{
|
||||||
_width_table_ table;
|
_width_table_ table;
|
||||||
hashed_escapement *deltas = new hashed_escapement[kTableCount];
|
hashed_escapement *deltas = new hashed_escapement[kTableCount];
|
||||||
#if B_BEOS_VERSION_DANO
|
|
||||||
table.font = font;
|
#if USE_DANO_WIDTHBUFFER
|
||||||
|
table.font = *font;
|
||||||
#else
|
#else
|
||||||
table.fontSize = font->Size();
|
table.fontSize = font->Size();
|
||||||
table.fontCode = font->FamilyAndStyle();
|
table.fontCode = font->FamilyAndStyle();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
table.hashCount = 0;
|
table.hashCount = 0;
|
||||||
table.tableCount = kTableCount;
|
table.tableCount = kTableCount;
|
||||||
table.widths = deltas;
|
table.widths = deltas;
|
||||||
@@ -237,8 +243,8 @@ _BWidthBuffer_::GetEscapement(uint32 value, int32 index, float *escapement)
|
|||||||
while ((found = widths[hashed].code) != (uint32)-1) {
|
while ((found = widths[hashed].code) != (uint32)-1) {
|
||||||
if (found == value)
|
if (found == value)
|
||||||
break;
|
break;
|
||||||
hashed++;
|
|
||||||
if (hashed >= (uint32)table->tableCount)
|
if (++hashed >= (uint32)table->tableCount)
|
||||||
hashed = 0;
|
hashed = 0;
|
||||||
DEBUG_ONLY(iterations++;)
|
DEBUG_ONLY(iterations++;)
|
||||||
}
|
}
|
||||||
@@ -311,12 +317,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 == (uint32)-1) {
|
if (found == (uint32)-1) {
|
||||||
// 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
|
||||||
@@ -351,6 +358,7 @@ _BWidthBuffer_::HashEscapements(const char *inText, int32 numChars, int32 textLe
|
|||||||
widths = newWidths;
|
widths = newWidths;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
charCount++;
|
charCount++;
|
||||||
offset += charLen;
|
offset += charLen;
|
||||||
} while (offset < textLen);
|
} while (offset < textLen);
|
||||||
|
|||||||
Reference in New Issue
Block a user