From a405a49e8291abe69af7f9034c12d3967d5d3c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 20 Oct 2005 10:01:49 +0000 Subject: [PATCH] * 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 --- headers/private/servers/app/FontFamily.h | 137 +++++++++++++---------- src/servers/app/FontFamily.cpp | 63 +++++------ src/servers/app/FontServer.cpp | 21 ++-- 3 files changed, 118 insertions(+), 103 deletions(-) diff --git a/headers/private/servers/app/FontFamily.h b/headers/private/servers/app/FontFamily.h index ff6f0c6408..42f43e61e3 100644 --- a/headers/private/servers/app/FontFamily.h +++ b/headers/private/servers/app/FontFamily.h @@ -53,14 +53,14 @@ enum font_format FONT_WINFONT, }; - +/* //! data structure used by the FreeType cache manager typedef struct CachedFaceRec_ { BString file_path; int face_index; } CachedFaceRec, *CachedFace; - +*/ /*! \brief Private structure to store font height values @@ -83,85 +83,104 @@ typedef struct FontStyle objects help abstract a lot of the font engine details while still offering plenty of information the style in question. */ -class FontStyle : public SharedObject -{ -public: - FontStyle(const char *filepath, FT_Face face); - ~FontStyle(); +class FontStyle : public SharedObject { + public: + FontStyle(const char* filepath, + FT_Face face); + virtual ~FontStyle(); /*! \fn bool FontStyle::IsFixedWidth(void) \brief Determines whether the font's character width is fixed \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) \brief Determines whether the font can be scaled to any size \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) \brief Determines whether the font has kerning information \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) \brief Determines whether the font contains strikes \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) \brief Returns 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) \brief Returns the number of glyphs in the style \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) \brief Returns the number of character maps the style contains \return The number of character maps the style contains */ - uint16 CharMapCount(void) const { return charmapcount; } - const char *Name() const; - FontFamily *Family() const { return family; } - uint16 GetID() const { return fID; } - int32 GetFlags() const; + inline uint16 CharMapCount() const + { return fFTFace->num_charmaps; } - uint16 GetFace() const { return fFace; } + const char* Name() const; + inline FontFamily* Family() const + { return fFontFamily; } + inline uint16 GetID() const + { return fID; } + int32 GetFlags() const; - const char *GetPath() const; - font_height GetHeight(const float &size) const; + inline uint16 GetFace() const + { return fFace; } + + const char* GetPath() 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 // 2.1.4 to 2.1.8 -// int16 ConvertToUnicode(uint16 c); +// int16 ConvertToUnicode(uint16 c); + + void AttachedToFamily(FontFamily* family); + void DetachedFromFamily(); + protected: - uint16 TranslateStyleToFace(const char *name) const; + uint16 TranslateStyleToFace(const char *name) const; 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; - uint8 format; - BRect fbounds; - uint16 fID; - uint16 fFace; - FontStyleHeight fHeight; + + FT_Face fFTFace; + // CachedFace cachedface; + + FontFamily* fFontFamily; + + BString fName; + BString fPath; + + BRect fBounds; + + uint16 fID; + uint16 fFace; + + FontStyleHeight fHeight; }; /*! @@ -171,31 +190,33 @@ protected: FontFamily objects bring together many styles of the same face, such as Arial Roman, Arial Italic, Arial Bold, etc. */ -class FontFamily : public SharedObject -{ -public: - FontFamily(const char *namestr, const uint16 &index); - ~FontFamily(); - const char *Name(); +class FontFamily : public SharedObject { + public: + FontFamily(const char* namestr, + const uint16& index); + virtual ~FontFamily(); + + const char* Name() const; - bool AddStyle(FontStyle *style); - void RemoveStyle(const char *style); - void RemoveStyle(FontStyle *style); - - FontStyle *GetStyle(int32 index) const; - FontStyle *GetStyle(const char *style) const; - - uint16 GetID() const { return fID; } - - bool HasStyle(const char *style) const; - int32 CountStyles() const; - int32 GetFlags(); + bool AddStyle(FontStyle* style); + void RemoveStyle(const char* style); + void RemoveStyle(FontStyle* style); + + FontStyle* GetStyle(int32 index) const; + FontStyle* GetStyle(const char* style) const; + + uint16 GetID() const + { return fID; } + + bool HasStyle(const char* style) const; + int32 CountStyles() const; + int32 GetFlags(); protected: - BString fName; - BList fStyles; - uint16 fID; - int32 fFlags; + BString fName; + BList fStyles; + uint16 fID; + int32 fFlags; }; #endif diff --git a/src/servers/app/FontFamily.cpp b/src/servers/app/FontFamily.cpp index fa4e863b96..a18be921ed 100644 --- a/src/servers/app/FontFamily.cpp +++ b/src/servers/app/FontFamily.cpp @@ -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 */ 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; - fName=face->style_name; - 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; +// cachedface = new CachedFaceRec; +// cachedface->file_path = filepath; + fHeight.ascent = face->ascender; - // FT2's descent numbers are negative. Be's is positive fHeight.descent = -face->descender; @@ -74,7 +67,10 @@ FontStyle::FontStyle(const char *filepath, FT_Face face) */ 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 */ const char* -FontFamily::Name() +FontFamily::Name() const { return fName.String(); } /*! \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 */ bool @@ -223,7 +218,7 @@ FontFamily::AddStyle(FontStyle *style) return false; } - style->family=this; + style->fFontFamily = this; if (fStyles.CountItems() > 0) { item = (FontStyle*)fStyles.ItemAt(fStyles.CountItems() - 1); @@ -246,26 +241,23 @@ FontFamily::AddStyle(FontStyle *style) \param style Name of the style to be removed from the family */ void -FontFamily::RemoveStyle(const char *style) +FontFamily::RemoveStyle(const char* style) { - int32 count=fStyles.CountItems(); - if(!style || count<1) + int32 count = fStyles.CountItems(); + if (!style || count < 1) return; FontStyle *fs; - for(int32 i=0; ifName.Compare(style)==0) - { - fs=(FontStyle *)fStyles.RemoveItem(i); - if(fs) - { + for (int32 i = 0; i < count; i++) { + fs = (FontStyle*)fStyles.ItemAt(i); + if (fs && fs->fName.Compare(style) == 0) { + if (fStyles.RemoveItem((void*)fs)) { delete fs; RemoveDependent(); // force a refresh if a request for font flags is needed - fFlags=-1; + fFlags = -1; + break; } } } @@ -276,10 +268,9 @@ FontFamily::RemoveStyle(const char *style) \param style The style to be removed from the family */ void -FontFamily::RemoveStyle(FontStyle *style) +FontFamily::RemoveStyle(FontStyle* style) { - if (fStyles.HasItem(style)) { - fStyles.RemoveItem(style); + if (fStyles.RemoveItem((void*)style)) { RemoveDependent(); // force a refresh if a request for font flags is needed diff --git a/src/servers/app/FontServer.cpp b/src/servers/app/FontServer.cpp index d65348659b..1c3a15376a 100644 --- a/src/servers/app/FontServer.cpp +++ b/src/servers/app/FontServer.cpp @@ -32,14 +32,14 @@ FontServer *gFontServer = NULL; /*! \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, FT_Pointer request_data, FT_Face *aface) { CachedFace face = (CachedFace) face_id; return FT_New_Face(ftlib, face->file_path.String(), face->face_index,aface); } - +*/ // #pragma mark - @@ -61,8 +61,8 @@ FontServer::FontServer(void) these numbers in the future to maximize performance for your "average" application. */ - if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0) - fInit = false; +// if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0) +// fInit = false; } @@ -257,11 +257,13 @@ FontServer::ScanDirectory(const char *directoryPath) family = new FontFamily(face->family_name, fFamilies.CountItems()); fFamilies.AddItem(family); - } - - if (family->HasStyle(face->style_name)) { - FT_Done_Face(face); - continue; + } else { + // prevent adding the same style twice + // (this indicates a problem with the installed fonts maybe?) + if (family->HasStyle(face->style_name)) { + FT_Done_Face(face); + continue; + } } #ifdef PRINT_FONT_LIST @@ -274,6 +276,7 @@ FontServer::ScanDirectory(const char *directoryPath) // FT_Face is kept open in FontStyle and will be unset in the // FontStyle destructor + // TODO: nope, it is not (yet) } fNeedUpdate = true;