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:
Stephan Aßmus 2005-05-20 17:36:55 +00:00
parent 097d641852
commit 38c5a7b7fa
4 changed files with 34 additions and 5 deletions

View File

@ -119,7 +119,9 @@ class ServerFont {
int32 numChars,
float widthArray[],
escapement_delta delta) const;
float StringWidth(const char* string, int32 numChars) const;
FT_Face GetFTFace() const
{ return fStyle->GetFTFace(); };

View File

@ -1783,7 +1783,10 @@ BTextView::PointAt(int32 inOffset, float *outHeight) const
result.x += modifier;
}
// convert from text rect coordinates
result.x += fTextRect.left - 1.0;
// NOTE: I didn't understand why "- 1.0"
// and it works only correct without it on Haiku app_server.
// Feel free to enlighten me though!
result.x += fTextRect.left;// - 1.0;
// round up
result.x = ceil(result.x);

View File

@ -1215,8 +1215,8 @@ ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg)
font.SetSize(size);
font.SetSpacing(spacing);
width = desktop->GetDisplayDriver()->StringWidth(string, length, font);
width = font.StringWidth(string, length);
replylink.StartMessage(SERVER_TRUE);
replylink.Attach<float>(width);
replylink.Flush();

View File

@ -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