diff --git a/headers/private/servers/app/ServerFont.h b/headers/private/servers/app/ServerFont.h index 74b77d54f8..f4063e8dbe 100644 --- a/headers/private/servers/app/ServerFont.h +++ b/headers/private/servers/app/ServerFont.h @@ -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(); }; diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index 03693ed36b..37172e0977 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -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); diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 5376b3fa2f..6c6d1ee7a1 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -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(width); replylink.Flush(); diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index dcb2d822d1..580a864a8c 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -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