From 9e7948f45e6b4ff830553c95a037e49f6b5dccd4 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 6 Feb 2006 17:42:18 +0000 Subject: [PATCH] * Fixed locking of the FT_Face by moving it into Get/PutTransformedFace() * Removed the FaceGetter as it was only needed for locking * Cleaned up TruncateString() * Fixed a typo in moreUTF8.h git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16252 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/moreUTF8.h | 2 +- src/servers/app/ServerFont.cpp | 79 ++++++++++------------------ 2 files changed, 30 insertions(+), 51 deletions(-) diff --git a/headers/private/interface/moreUTF8.h b/headers/private/interface/moreUTF8.h index ae23d947dd..eb8b074fca 100644 --- a/headers/private/interface/moreUTF8.h +++ b/headers/private/interface/moreUTF8.h @@ -115,7 +115,7 @@ UTF8ToCharCode(const char **bytes) if ((*bytes)[0] & 0x10) { if ((*bytes)[0] & 0x08) { /* A five byte char?! - Something's wrong, substitue. */ + Something's wrong, substitute. */ result += 0x20; (*bytes)++; return result; diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 739e99178e..5a2022f7ac 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -9,7 +9,6 @@ */ -#include #include #include #include @@ -94,33 +93,6 @@ is_white_space(uint16 glyph) // #pragma mark - -class FaceGetter { - public: - FaceGetter(FontStyle *style) - : - fStyle(style) - { - style->Lock(); - } - - ~FaceGetter() - { - fStyle->Unlock(); - } - - FT_Face Face() - { - return fStyle->FreeTypeFace(); - } - - private: - FontStyle *fStyle; -}; - - -// #pragma mark - - - /*! \brief Constructor \param style Style object to which the ServerFont belongs @@ -322,10 +294,12 @@ ServerFont::GetFamilyAndStyle() const FT_Face ServerFont::GetTransformedFace(bool rotate, bool shear) const { - FaceGetter getter(fStyle); - FT_Face face = getter.Face(); - if (!face) + fStyle->Lock(); + FT_Face face = fStyle->FreeTypeFace(); + if (!face) { + fStyle->Unlock(); return NULL; + } FT_Set_Char_Size(face, 0, int32(fSize * 64), 72, 72); @@ -357,7 +331,8 @@ void ServerFont::PutTransformedFace(FT_Face face) const { // Reset transformation - FT_Set_Transform(face, NULL, NULL); + FT_Set_Transform(face, NULL, NULL); + fStyle->Unlock(); } @@ -612,27 +587,31 @@ ServerFont::GetHeight(font_height& height) const void ServerFont::TruncateString(BString* inOut, uint32 mode, float width) const { - if (inOut) { - // the width of the "…" glyph - float ellipsisWidth = StringWidth(B_UTF8_ELLIPSIS, 3); - const char* string = inOut->String(); - int32 length = strlen(string); - // temporary array to hold result - char* result = new char[length + 3]; - // count the individual glyphs - int32 numChars = UTF8CountChars(string, length); - // get the escapement of each glyph in font units - float* escapementArray = new float[numChars]; - static escapement_delta delta = (escapement_delta){ 0.0, 0.0 }; - GetEscapements(string, numChars, delta, escapementArray); + if (!inOut) + return; - truncate_string(string, mode, width, result, - escapementArray, fSize, ellipsisWidth, length, numChars); + // the width of the "…" glyph + float ellipsisWidth = StringWidth(B_UTF8_ELLIPSIS, 1); + const char *string = inOut->String(); + int32 length = inOut->Length(); + + // temporary array to hold result + char *result = new char[length + 3]; + + // count the individual glyphs + int32 numChars = UTF8ToLength(string); + + // get the escapement of each glyph in font units + float *escapementArray = new float[numChars]; + static escapement_delta delta = (escapement_delta){ 0.0, 0.0 }; + if (GetEscapements(string, numChars, delta, escapementArray) == B_OK) { + truncate_string(string, mode, width, result, escapementArray, fSize, + ellipsisWidth, length, numChars); inOut->SetTo(result); - - delete[] escapementArray; - delete[] result; } + + delete[] escapementArray; + delete[] result; }