* 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
This commit is contained in:
@@ -115,7 +115,7 @@ UTF8ToCharCode(const char **bytes)
|
|||||||
if ((*bytes)[0] & 0x10) {
|
if ((*bytes)[0] & 0x10) {
|
||||||
if ((*bytes)[0] & 0x08) {
|
if ((*bytes)[0] & 0x08) {
|
||||||
/* A five byte char?!
|
/* A five byte char?!
|
||||||
Something's wrong, substitue. */
|
Something's wrong, substitute. */
|
||||||
result += 0x20;
|
result += 0x20;
|
||||||
(*bytes)++;
|
(*bytes)++;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <UTF8.h>
|
#include <UTF8.h>
|
||||||
@@ -94,33 +93,6 @@ is_white_space(uint16 glyph)
|
|||||||
// #pragma mark -
|
// #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
|
\brief Constructor
|
||||||
\param style Style object to which the ServerFont belongs
|
\param style Style object to which the ServerFont belongs
|
||||||
@@ -322,10 +294,12 @@ ServerFont::GetFamilyAndStyle() const
|
|||||||
FT_Face
|
FT_Face
|
||||||
ServerFont::GetTransformedFace(bool rotate, bool shear) const
|
ServerFont::GetTransformedFace(bool rotate, bool shear) const
|
||||||
{
|
{
|
||||||
FaceGetter getter(fStyle);
|
fStyle->Lock();
|
||||||
FT_Face face = getter.Face();
|
FT_Face face = fStyle->FreeTypeFace();
|
||||||
if (!face)
|
if (!face) {
|
||||||
|
fStyle->Unlock();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
FT_Set_Char_Size(face, 0, int32(fSize * 64), 72, 72);
|
FT_Set_Char_Size(face, 0, int32(fSize * 64), 72, 72);
|
||||||
|
|
||||||
@@ -357,7 +331,8 @@ void
|
|||||||
ServerFont::PutTransformedFace(FT_Face face) const
|
ServerFont::PutTransformedFace(FT_Face face) const
|
||||||
{
|
{
|
||||||
// Reset transformation
|
// 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
|
void
|
||||||
ServerFont::TruncateString(BString* inOut, uint32 mode, float width) const
|
ServerFont::TruncateString(BString* inOut, uint32 mode, float width) const
|
||||||
{
|
{
|
||||||
if (inOut) {
|
if (!inOut)
|
||||||
// the width of the "…" glyph
|
return;
|
||||||
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);
|
|
||||||
|
|
||||||
truncate_string(string, mode, width, result,
|
// the width of the "…" glyph
|
||||||
escapementArray, fSize, ellipsisWidth, length, numChars);
|
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);
|
inOut->SetTo(result);
|
||||||
|
|
||||||
delete[] escapementArray;
|
|
||||||
delete[] result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] escapementArray;
|
||||||
|
delete[] result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user