* cleaned up and applied coding style to FontStyle
* got rid of bogus member variables in FontStyle (which were already flags in the underlying FT_Face structure) * disabled using the FreeType font cache -> I think from my earlier tests, I can conclude that the cache was not actually working. At least not giving any speed improvements. The AGG engine contains a caching system, for now, it works ok. I have no idea if this has anything to do with crashes in the freetype code, but at least I have not seen any since this change. But I have not tested much... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14448 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -53,14 +53,14 @@ enum font_format
|
|||||||
FONT_WINFONT,
|
FONT_WINFONT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
//! data structure used by the FreeType cache manager
|
//! data structure used by the FreeType cache manager
|
||||||
typedef struct CachedFaceRec_
|
typedef struct CachedFaceRec_
|
||||||
{
|
{
|
||||||
BString file_path;
|
BString file_path;
|
||||||
int face_index;
|
int face_index;
|
||||||
} CachedFaceRec, *CachedFace;
|
} CachedFaceRec, *CachedFace;
|
||||||
|
*/
|
||||||
/*!
|
/*!
|
||||||
\brief Private structure to store font height values
|
\brief Private structure to store font height values
|
||||||
|
|
||||||
@@ -83,84 +83,103 @@ typedef struct
|
|||||||
FontStyle objects help abstract a lot of the font engine details while
|
FontStyle objects help abstract a lot of the font engine details while
|
||||||
still offering plenty of information the style in question.
|
still offering plenty of information the style in question.
|
||||||
*/
|
*/
|
||||||
class FontStyle : public SharedObject
|
class FontStyle : public SharedObject {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
FontStyle(const char *filepath, FT_Face face);
|
FontStyle(const char* filepath,
|
||||||
~FontStyle();
|
FT_Face face);
|
||||||
|
virtual ~FontStyle();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::IsFixedWidth(void)
|
\fn bool FontStyle::IsFixedWidth(void)
|
||||||
\brief Determines whether the font's character width is fixed
|
\brief Determines whether the font's character width is fixed
|
||||||
\return true if fixed, false if not
|
\return true if fixed, false if not
|
||||||
*/
|
*/
|
||||||
bool IsFixedWidth() const { return is_fixedwidth; }
|
inline bool IsFixedWidth() const
|
||||||
|
{ return fFTFace->face_flags & FT_FACE_FLAG_FIXED_WIDTH; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::IsScalable(void)
|
\fn bool FontStyle::IsScalable(void)
|
||||||
\brief Determines whether the font can be scaled to any size
|
\brief Determines whether the font can be scaled to any size
|
||||||
\return true if scalable, false if not
|
\return true if scalable, false if not
|
||||||
*/
|
*/
|
||||||
bool IsScalable() const { return is_scalable; }
|
inline bool IsScalable() const
|
||||||
|
{ return fFTFace->face_flags & FT_FACE_FLAG_SCALABLE; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::HasKerning(void)
|
\fn bool FontStyle::HasKerning(void)
|
||||||
\brief Determines whether the font has kerning information
|
\brief Determines whether the font has kerning information
|
||||||
\return true if kerning info is available, false if not
|
\return true if kerning info is available, false if not
|
||||||
*/
|
*/
|
||||||
bool HasKerning() const { return has_kerning; }
|
inline bool HasKerning() const
|
||||||
|
{ return fFTFace->face_flags & FT_FACE_FLAG_KERNING; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::HasTuned(void)
|
\fn bool FontStyle::HasTuned(void)
|
||||||
\brief Determines whether the font contains strikes
|
\brief Determines whether the font contains strikes
|
||||||
\return true if it has strikes included, false if not
|
\return true if it has strikes included, false if not
|
||||||
*/
|
*/
|
||||||
bool HasTuned() const { return has_bitmaps; }
|
inline bool HasTuned() const
|
||||||
|
{ return fFTFace->num_fixed_sizes > 0; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::TunedCount(void)
|
\fn bool FontStyle::TunedCount(void)
|
||||||
\brief Returns the number of strikes the style contains
|
\brief Returns the number of strikes the style contains
|
||||||
\return The number of strikes the style contains
|
\return The number of strikes the style contains
|
||||||
*/
|
*/
|
||||||
int32 TunedCount() const { return tunedcount; }
|
inline int32 TunedCount() const
|
||||||
|
{ return fFTFace->num_fixed_sizes; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::GlyphCount(void)
|
\fn bool FontStyle::GlyphCount(void)
|
||||||
\brief Returns the number of glyphs in the style
|
\brief Returns the number of glyphs in the style
|
||||||
\return The number of glyphs the style contains
|
\return The number of glyphs the style contains
|
||||||
*/
|
*/
|
||||||
uint16 GlyphCount() const { return glyphcount; }
|
inline uint16 GlyphCount() const
|
||||||
|
{ return fFTFace->num_glyphs; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::CharMapCount(void)
|
\fn bool FontStyle::CharMapCount(void)
|
||||||
\brief Returns the number of character maps the style contains
|
\brief Returns the number of character maps the style contains
|
||||||
\return The number of character maps the style contains
|
\return The number of character maps the style contains
|
||||||
*/
|
*/
|
||||||
uint16 CharMapCount(void) const { return charmapcount; }
|
inline uint16 CharMapCount() const
|
||||||
|
{ return fFTFace->num_charmaps; }
|
||||||
|
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
FontFamily *Family() const { return family; }
|
inline FontFamily* Family() const
|
||||||
uint16 GetID() const { return fID; }
|
{ return fFontFamily; }
|
||||||
|
inline uint16 GetID() const
|
||||||
|
{ return fID; }
|
||||||
int32 GetFlags() const;
|
int32 GetFlags() const;
|
||||||
|
|
||||||
uint16 GetFace() const { return fFace; }
|
inline uint16 GetFace() const
|
||||||
|
{ return fFace; }
|
||||||
|
|
||||||
const char* GetPath() const;
|
const char* GetPath() const;
|
||||||
font_height GetHeight(const float& size) const;
|
font_height GetHeight(const float& size) const;
|
||||||
|
|
||||||
FT_Face GetFTFace() const { return fFTFace; }
|
inline FT_Face GetFTFace() const
|
||||||
|
{ return fFTFace; }
|
||||||
|
|
||||||
// TODO: Re-enable when I understand how the FT2 Cache system changed from
|
// TODO: Re-enable when I understand how the FT2 Cache system changed from
|
||||||
// 2.1.4 to 2.1.8
|
// 2.1.4 to 2.1.8
|
||||||
// int16 ConvertToUnicode(uint16 c);
|
// int16 ConvertToUnicode(uint16 c);
|
||||||
|
|
||||||
|
void AttachedToFamily(FontFamily* family);
|
||||||
|
void DetachedFromFamily();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16 TranslateStyleToFace(const char *name) const;
|
uint16 TranslateStyleToFace(const char *name) const;
|
||||||
|
|
||||||
friend class FontFamily;
|
friend class FontFamily;
|
||||||
FontFamily *family;
|
|
||||||
uint16 glyphcount, charmapcount;
|
|
||||||
BString fName, fPath;
|
|
||||||
bool is_fixedwidth, is_scalable, has_kerning, has_bitmaps;
|
|
||||||
int32 tunedcount;
|
|
||||||
CachedFace cachedface;
|
|
||||||
FT_Face fFTFace;
|
FT_Face fFTFace;
|
||||||
uint8 format;
|
// CachedFace cachedface;
|
||||||
BRect fbounds;
|
|
||||||
|
FontFamily* fFontFamily;
|
||||||
|
|
||||||
|
BString fName;
|
||||||
|
BString fPath;
|
||||||
|
|
||||||
|
BRect fBounds;
|
||||||
|
|
||||||
uint16 fID;
|
uint16 fID;
|
||||||
uint16 fFace;
|
uint16 fFace;
|
||||||
|
|
||||||
FontStyleHeight fHeight;
|
FontStyleHeight fHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,12 +190,13 @@ protected:
|
|||||||
FontFamily objects bring together many styles of the same face, such as
|
FontFamily objects bring together many styles of the same face, such as
|
||||||
Arial Roman, Arial Italic, Arial Bold, etc.
|
Arial Roman, Arial Italic, Arial Bold, etc.
|
||||||
*/
|
*/
|
||||||
class FontFamily : public SharedObject
|
class FontFamily : public SharedObject {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
FontFamily(const char *namestr, const uint16 &index);
|
FontFamily(const char* namestr,
|
||||||
~FontFamily();
|
const uint16& index);
|
||||||
const char *Name();
|
virtual ~FontFamily();
|
||||||
|
|
||||||
|
const char* Name() const;
|
||||||
|
|
||||||
bool AddStyle(FontStyle* style);
|
bool AddStyle(FontStyle* style);
|
||||||
void RemoveStyle(const char* style);
|
void RemoveStyle(const char* style);
|
||||||
@@ -185,7 +205,8 @@ public:
|
|||||||
FontStyle* GetStyle(int32 index) const;
|
FontStyle* GetStyle(int32 index) const;
|
||||||
FontStyle* GetStyle(const char* style) const;
|
FontStyle* GetStyle(const char* style) const;
|
||||||
|
|
||||||
uint16 GetID() const { return fID; }
|
uint16 GetID() const
|
||||||
|
{ return fID; }
|
||||||
|
|
||||||
bool HasStyle(const char* style) const;
|
bool HasStyle(const char* style) const;
|
||||||
int32 CountStyles() const;
|
int32 CountStyles() const;
|
||||||
|
|||||||
@@ -36,25 +36,18 @@ FTC_Manager ftmanager;
|
|||||||
\param face FreeType handle for the font file after it is loaded - it will be kept open until the FontStyle is destroied
|
\param face FreeType handle for the font file after it is loaded - it will be kept open until the FontStyle is destroied
|
||||||
*/
|
*/
|
||||||
FontStyle::FontStyle(const char *filepath, FT_Face face)
|
FontStyle::FontStyle(const char *filepath, FT_Face face)
|
||||||
|
: fFTFace(face),
|
||||||
|
fFontFamily(NULL),
|
||||||
|
fName(face->style_name),
|
||||||
|
fPath(filepath),
|
||||||
|
fBounds(0, 0, 0, 0),
|
||||||
|
fID(0),
|
||||||
|
fFace(TranslateStyleToFace(face->style_name))
|
||||||
{
|
{
|
||||||
fFTFace = face;
|
// cachedface = new CachedFaceRec;
|
||||||
fName=face->style_name;
|
// cachedface->file_path = filepath;
|
||||||
cachedface=new CachedFaceRec;
|
|
||||||
cachedface->file_path=filepath;
|
|
||||||
family=NULL;
|
|
||||||
has_bitmaps=(face->num_fixed_sizes>0)?true:false;
|
|
||||||
is_fixedwidth=(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH)?true:false;
|
|
||||||
is_scalable=(face->face_flags & FT_FACE_FLAG_SCALABLE)?true:false;
|
|
||||||
has_kerning=(face->face_flags & FT_FACE_FLAG_KERNING)?true:false;
|
|
||||||
glyphcount=face->num_glyphs;
|
|
||||||
charmapcount=face->num_charmaps;
|
|
||||||
tunedcount=face->num_fixed_sizes;
|
|
||||||
fPath=filepath;
|
|
||||||
fbounds.Set(0,0,0,0);
|
|
||||||
fFace=TranslateStyleToFace(face->style_name);
|
|
||||||
fID=0;
|
|
||||||
fHeight.ascent = face->ascender;
|
|
||||||
|
|
||||||
|
fHeight.ascent = face->ascender;
|
||||||
// FT2's descent numbers are negative. Be's is positive
|
// FT2's descent numbers are negative. Be's is positive
|
||||||
fHeight.descent = -face->descender;
|
fHeight.descent = -face->descender;
|
||||||
|
|
||||||
@@ -74,7 +67,10 @@ FontStyle::FontStyle(const char *filepath, FT_Face face)
|
|||||||
*/
|
*/
|
||||||
FontStyle::~FontStyle()
|
FontStyle::~FontStyle()
|
||||||
{
|
{
|
||||||
delete cachedface;
|
// TODO: what was the purpose of this?
|
||||||
|
// delete cachedface;
|
||||||
|
// TODO: figure out if it is safe to call this:
|
||||||
|
// FT_Done_Face(fFTFace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -197,14 +193,13 @@ FontFamily::~FontFamily()
|
|||||||
\return The family's name
|
\return The family's name
|
||||||
*/
|
*/
|
||||||
const char*
|
const char*
|
||||||
FontFamily::Name()
|
FontFamily::Name() const
|
||||||
{
|
{
|
||||||
return fName.String();
|
return fName.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Adds the style to the family
|
\brief Adds the style to the family
|
||||||
\param path full path to the style's font file
|
|
||||||
\param face FreeType face handle used to obtain info about the font
|
\param face FreeType face handle used to obtain info about the font
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
@@ -223,7 +218,7 @@ FontFamily::AddStyle(FontStyle *style)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
style->family=this;
|
style->fFontFamily = this;
|
||||||
|
|
||||||
if (fStyles.CountItems() > 0) {
|
if (fStyles.CountItems() > 0) {
|
||||||
item = (FontStyle*)fStyles.ItemAt(fStyles.CountItems() - 1);
|
item = (FontStyle*)fStyles.ItemAt(fStyles.CountItems() - 1);
|
||||||
@@ -253,19 +248,16 @@ FontFamily::RemoveStyle(const char *style)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
FontStyle *fs;
|
FontStyle *fs;
|
||||||
for(int32 i=0; i<count; i++)
|
for (int32 i = 0; i < count; i++) {
|
||||||
{
|
|
||||||
fs = (FontStyle*)fStyles.ItemAt(i);
|
fs = (FontStyle*)fStyles.ItemAt(i);
|
||||||
if(fs && fs->fName.Compare(style)==0)
|
if (fs && fs->fName.Compare(style) == 0) {
|
||||||
{
|
if (fStyles.RemoveItem((void*)fs)) {
|
||||||
fs=(FontStyle *)fStyles.RemoveItem(i);
|
|
||||||
if(fs)
|
|
||||||
{
|
|
||||||
delete fs;
|
delete fs;
|
||||||
RemoveDependent();
|
RemoveDependent();
|
||||||
|
|
||||||
// force a refresh if a request for font flags is needed
|
// force a refresh if a request for font flags is needed
|
||||||
fFlags = -1;
|
fFlags = -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,8 +270,7 @@ FontFamily::RemoveStyle(const char *style)
|
|||||||
void
|
void
|
||||||
FontFamily::RemoveStyle(FontStyle* style)
|
FontFamily::RemoveStyle(FontStyle* style)
|
||||||
{
|
{
|
||||||
if (fStyles.HasItem(style)) {
|
if (fStyles.RemoveItem((void*)style)) {
|
||||||
fStyles.RemoveItem(style);
|
|
||||||
RemoveDependent();
|
RemoveDependent();
|
||||||
|
|
||||||
// force a refresh if a request for font flags is needed
|
// force a refresh if a request for font flags is needed
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ FontServer *gFontServer = NULL;
|
|||||||
/*!
|
/*!
|
||||||
\brief Access function to request a face via the FreeType font cache
|
\brief Access function to request a face via the FreeType font cache
|
||||||
*/
|
*/
|
||||||
static FT_Error
|
/*static FT_Error
|
||||||
face_requester(FTC_FaceID face_id, FT_Library library,
|
face_requester(FTC_FaceID face_id, FT_Library library,
|
||||||
FT_Pointer request_data, FT_Face *aface)
|
FT_Pointer request_data, FT_Face *aface)
|
||||||
{
|
{
|
||||||
CachedFace face = (CachedFace) face_id;
|
CachedFace face = (CachedFace) face_id;
|
||||||
return FT_New_Face(ftlib, face->file_path.String(), face->face_index,aface);
|
return FT_New_Face(ftlib, face->file_path.String(), face->face_index,aface);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
@@ -61,8 +61,8 @@ FontServer::FontServer(void)
|
|||||||
these numbers in the future to maximize performance for your "average"
|
these numbers in the future to maximize performance for your "average"
|
||||||
application.
|
application.
|
||||||
*/
|
*/
|
||||||
if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0)
|
// if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0)
|
||||||
fInit = false;
|
// fInit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -257,12 +257,14 @@ FontServer::ScanDirectory(const char *directoryPath)
|
|||||||
|
|
||||||
family = new FontFamily(face->family_name, fFamilies.CountItems());
|
family = new FontFamily(face->family_name, fFamilies.CountItems());
|
||||||
fFamilies.AddItem(family);
|
fFamilies.AddItem(family);
|
||||||
}
|
} else {
|
||||||
|
// prevent adding the same style twice
|
||||||
|
// (this indicates a problem with the installed fonts maybe?)
|
||||||
if (family->HasStyle(face->style_name)) {
|
if (family->HasStyle(face->style_name)) {
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PRINT_FONT_LIST
|
#ifdef PRINT_FONT_LIST
|
||||||
printf("\tFont Style: %s\n", face->style_name);
|
printf("\tFont Style: %s\n", face->style_name);
|
||||||
@@ -274,6 +276,7 @@ FontServer::ScanDirectory(const char *directoryPath)
|
|||||||
|
|
||||||
// FT_Face is kept open in FontStyle and will be unset in the
|
// FT_Face is kept open in FontStyle and will be unset in the
|
||||||
// FontStyle destructor
|
// FontStyle destructor
|
||||||
|
// TODO: nope, it is not (yet)
|
||||||
}
|
}
|
||||||
|
|
||||||
fNeedUpdate = true;
|
fNeedUpdate = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user