Implemented StringWidth in ServerFont, updated ServerApp to use it, and removed a -1 from TextView in the char location calculation, which I didn't understand and without which the cursor location and related stuff now finally work.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12744 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -290,6 +290,7 @@ ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const
|
||||
return shapes;
|
||||
}
|
||||
|
||||
// GetEscapements
|
||||
BPoint*
|
||||
ServerFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
BPoint offsetArray[]) const
|
||||
@@ -353,6 +354,7 @@ is_white_space(uint16 glyph)
|
||||
return false;
|
||||
}
|
||||
|
||||
// GetEscapements
|
||||
bool
|
||||
ServerFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
float widthArray[], escapement_delta delta) const
|
||||
@@ -389,7 +391,7 @@ ServerFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
for (int i = 0; i < numChars; i++) {
|
||||
FT_Load_Char(face, glyphIndex[i], FT_LOAD_NO_BITMAP);
|
||||
// widthArray[i] = float(face->glyph->metrics.width / 64) / fSize;
|
||||
widthArray[i] = float(face->glyph->metrics.horiAdvance / 64) / fSize;
|
||||
widthArray[i] = ((float)face->glyph->metrics.horiAdvance / 64.0) / fSize;
|
||||
widthArray[i] += is_white_space(glyphIndex[i]) ? delta.space : delta.nonspace;
|
||||
}
|
||||
}
|
||||
@@ -398,6 +400,28 @@ ServerFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
return ret >= B_OK;
|
||||
}
|
||||
|
||||
// StringWidth
|
||||
float
|
||||
ServerFont::StringWidth(const char* string, int32 numChars) const
|
||||
{
|
||||
// TODO: we're lazy for now and reuse the existing
|
||||
// functionality in GetEscapements
|
||||
escapement_delta delta;
|
||||
delta.space = 0.0;
|
||||
delta.nonspace = 0.0;
|
||||
|
||||
float* widthArray = new float[numChars];
|
||||
|
||||
GetEscapements(string, numChars, widthArray, delta);
|
||||
float width = 0.0;
|
||||
for (int32 i = 0; i < numChars; i++)
|
||||
width += widthArray[i] * fSize;
|
||||
|
||||
delete[] widthArray;
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Sets the ServerFont instance to whatever font is specified
|
||||
\param familyID ID number of the family to set
|
||||
|
||||
Reference in New Issue
Block a user