large cleanup, should have fixed some memory leaks too

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12942 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2005-06-03 19:30:32 +00:00
parent 8359877941
commit 11f97ed147
2 changed files with 90 additions and 87 deletions

View File

@ -87,59 +87,59 @@ class FontStyle : public SharedObject
{ {
public: public:
FontStyle(const char *filepath, FT_Face face); FontStyle(const char *filepath, FT_Face face);
~FontStyle(void); ~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(void) const { return is_fixedwidth; } bool IsFixedWidth() const { return is_fixedwidth; }
/*! /*!
\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(void) const { return is_scalable; } bool IsScalable() const { return is_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(void) const { return has_kerning; } bool HasKerning() const { return has_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(void) const { return has_bitmaps; } bool HasTuned() const { return has_bitmaps; }
/*! /*!
\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(void) const { return tunedcount; } int32 TunedCount() const { return tunedcount; }
/*! /*!
\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(void) const { return glyphcount; } uint16 GlyphCount() const { return glyphcount; }
/*! /*!
\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; } uint16 CharMapCount(void) const { return charmapcount; }
const char *Name(void) const; const char *Name() const;
FontFamily *Family(void) const { return family; } FontFamily *Family() const { return family; }
uint16 GetID(void) const { return fID; } uint16 GetID() const { return fID; }
int32 GetFlags(void) const; int32 GetFlags() const;
uint16 GetFace(void) const { return fFace; } uint16 GetFace() const { return fFace; }
const char *GetPath(void); const char *GetPath() const;
font_height GetHeight(const float &size); font_height GetHeight(const float &size) const;
FT_Face GetFTFace() const { return fFTFace; } FT_Face GetFTFace() const { return fFTFace; }
@ -175,21 +175,21 @@ class FontFamily : public SharedObject
{ {
public: public:
FontFamily(const char *namestr, const uint16 &index); FontFamily(const char *namestr, const uint16 &index);
~FontFamily(void); ~FontFamily();
const char *Name(void); const char *Name();
bool AddStyle(FontStyle *style); bool AddStyle(FontStyle *style);
void RemoveStyle(const char *style); void RemoveStyle(const char *style);
void RemoveStyle(FontStyle *style); void RemoveStyle(FontStyle *style);
FontStyle *GetStyle(int32 index); FontStyle *GetStyle(int32 index) const;
FontStyle *GetStyle(const char *style); FontStyle *GetStyle(const char *style) const;
uint16 GetID(void) const { return fID; } uint16 GetID() const { return fID; }
bool HasStyle(const char *style); bool HasStyle(const char *style) const;
int32 CountStyles(void); int32 CountStyles() const;
int32 GetFlags(void); int32 GetFlags();
protected: protected:
BString fName; BString fName;

View File

@ -72,7 +72,7 @@ FontStyle::FontStyle(const char *filepath, FT_Face face)
This is done because a FontStyle should be deleted only when it no longer has any This is done because a FontStyle should be deleted only when it no longer has any
dependencies. dependencies.
*/ */
FontStyle::~FontStyle(void) FontStyle::~FontStyle()
{ {
delete cachedface; delete cachedface;
} }
@ -81,14 +81,16 @@ FontStyle::~FontStyle(void)
\brief Returns the name of the style as a string \brief Returns the name of the style as a string
\return The style's name \return The style's name
*/ */
const char *FontStyle::Name(void) const const char*
FontStyle::Name() const
{ {
return fName.String(); return fName.String();
} }
font_height FontStyle::GetHeight(const float &size) font_height
FontStyle::GetHeight(const float &size) const
{ {
font_height fh={0,0,0}; font_height fh = { 0, 0, 0 };
// font units are 26.6 format, so we get REALLY big numbers if // font units are 26.6 format, so we get REALLY big numbers if
// we don't do some shifting. // we don't do some shifting.
@ -105,12 +107,14 @@ font_height FontStyle::GetHeight(const float &size)
\brief Returns the path to the style's font file \brief Returns the path to the style's font file
\return The style's font file path \return The style's font file path
*/ */
const char *FontStyle::GetPath(void) const char*
FontStyle::GetPath() const
{ {
return fPath.String(); return fPath.String();
} }
int32 FontStyle::GetFlags(void) const int32
FontStyle::GetFlags() const
{ {
int32 flags=0; int32 flags=0;
if(IsFixedWidth()) if(IsFixedWidth())
@ -141,7 +145,8 @@ int16 FontStyle::ConvertToUnicode(uint16 c)
} }
*/ */
uint16 FontStyle::TranslateStyleToFace(const char *name) const uint16
FontStyle::TranslateStyleToFace(const char *name) const
{ {
if(!name) if(!name)
return 0; return 0;
@ -166,11 +171,11 @@ uint16 FontStyle::TranslateStyleToFace(const char *name) const
*/ */
FontFamily::FontFamily(const char *namestr, const uint16 &index) FontFamily::FontFamily(const char *namestr, const uint16 &index)
{ {
fName=namestr; fName = namestr;
fID=index; fID = index;
// will stay uninitialized until needed // will stay uninitialized until needed
fFlags=-1; fFlags = -1;
} }
/*! /*!
@ -180,21 +185,19 @@ FontFamily::FontFamily(const char *namestr, const uint16 &index)
its styles have no dependencies or some other really good reason, such as its styles have no dependencies or some other really good reason, such as
system shutdown. system shutdown.
*/ */
FontFamily::~FontFamily(void) FontFamily::~FontFamily()
{ {
FontStyle *style; int32 count = fStyles.CountItems();
for(int32 i=0; i<fStyles.CountItems(); i++) for (int32 i = 0; i < count; i++)
{ delete (FontStyle*)fStyles.ItemAt(i);
style=(FontStyle *)fStyles.RemoveItem(i);
delete style;
}
} }
/*! /*!
\brief Returns the name of the family \brief Returns the name of the family
\return The family's name \return The family's name
*/ */
const char *FontFamily::Name(void) const char*
FontFamily::Name()
{ {
return fName.String(); return fName.String();
} }
@ -204,31 +207,30 @@ const char *FontFamily::Name(void)
\param path full path to the style's font file \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 FontFamily::AddStyle(FontStyle *style) bool
FontFamily::AddStyle(FontStyle *style)
{ {
if(!style) if (!style)
return false; return false;
FontStyle *item; FontStyle *item;
// Don't add if it already is in the family. // Don't add if it already is in the family.
int32 count=fStyles.CountItems(); int32 count = fStyles.CountItems();
for(int32 i=0; i<count; i++) for(int32 i = 0; i < count; i++) {
{ item = (FontStyle*)fStyles.ItemAt(i);
item=(FontStyle *)fStyles.ItemAt(i); if (item->fName == style->fName)
if(item->fName==style->fName)
return false; return false;
} }
style->family=this; style->family=this;
if(fStyles.CountItems()>0) if (fStyles.CountItems() > 0) {
{ item = (FontStyle*)fStyles.ItemAt(fStyles.CountItems() - 1);
item=(FontStyle *)fStyles.ItemAt(fStyles.CountItems()-1); style->fID = item->fID + 1;
style->fID=item->fID+1; } else {
style->fID = 0;
} }
else
style->fID=0;
fStyles.AddItem(style); fStyles.AddItem(style);
AddDependent(); AddDependent();
@ -243,7 +245,8 @@ bool FontFamily::AddStyle(FontStyle *style)
\brief Removes a style from the family and deletes it \brief Removes a style from the family and deletes it
\param style Name of the style to be removed from the family \param style Name of the style to be removed from the family
*/ */
void FontFamily::RemoveStyle(const char *style) void
FontFamily::RemoveStyle(const char *style)
{ {
int32 count=fStyles.CountItems(); int32 count=fStyles.CountItems();
if(!style || count<1) if(!style || count<1)
@ -272,15 +275,15 @@ void FontFamily::RemoveStyle(const char *style)
\brief Removes a style from the family. The caller is responsible for freeing the object \brief Removes a style from the family. The caller is responsible for freeing the object
\param style The style to be removed from the family \param style The style to be removed from the family
*/ */
void FontFamily::RemoveStyle(FontStyle *style) void
FontFamily::RemoveStyle(FontStyle *style)
{ {
if(fStyles.HasItem(style)) if (fStyles.HasItem(style)) {
{
fStyles.RemoveItem(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
fFlags=-1; fFlags = -1;
} }
} }
@ -288,7 +291,8 @@ void FontFamily::RemoveStyle(FontStyle *style)
\brief Returns the number of styles in the family \brief Returns the number of styles in the family
\return The number of styles in the family \return The number of styles in the family
*/ */
int32 FontFamily::CountStyles(void) int32
FontFamily::CountStyles() const
{ {
return fStyles.CountItems(); return fStyles.CountItems();
} }
@ -298,18 +302,18 @@ int32 FontFamily::CountStyles(void)
\param style Name of the style being checked \param style Name of the style being checked
\return True if it belongs, false if not \return True if it belongs, false if not
*/ */
bool FontFamily::HasStyle(const char *style) bool
FontFamily::HasStyle(const char *style) const
{ {
int32 count=fStyles.CountItems(); int32 count = fStyles.CountItems();
if(!style || count<1) if (!style || count < 1)
return false; return false;
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)
return true; return true;
} }
return false; return false;
@ -320,7 +324,8 @@ bool FontFamily::HasStyle(const char *style)
\param index list index of the style to be found \param index list index of the style to be found
\return name of the style or NULL if the index is not valid \return name of the style or NULL if the index is not valid
*/ */
FontStyle *FontFamily::GetStyle(int32 index) FontStyle*
FontFamily::GetStyle(int32 index) const
{ {
return (FontStyle*)fStyles.ItemAt(index); return (FontStyle*)fStyles.ItemAt(index);
} }
@ -332,40 +337,38 @@ FontStyle *FontFamily::GetStyle(int32 index)
The object returned belongs to the family and must not be deleted. The object returned belongs to the family and must not be deleted.
*/ */
FontStyle *FontFamily::GetStyle(const char *style) FontStyle*
FontFamily::GetStyle(const char *style) const
{ {
int32 count=fStyles.CountItems(); int32 count=fStyles.CountItems();
if(!style || count<1) if (!style || count < 1)
return NULL; return NULL;
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)
return fs; return fs;
} }
return NULL; return NULL;
} }
int32 FontFamily::GetFlags(void) int32
FontFamily::GetFlags()
{ {
if(fFlags==-1) if (fFlags == -1) {
{ fFlags = 0;
fFlags=0;
for(int32 i=0; i<fStyles.CountItems(); i++) for (int32 i = 0; i < fStyles.CountItems(); i++) {
{ FontStyle* style = (FontStyle*)fStyles.ItemAt(i);
FontStyle *style=(FontStyle*)fStyles.ItemAt(i); if (style) {
if(style) if (style->IsFixedWidth())
{ fFlags |= B_IS_FIXED;
if(style->IsFixedWidth()) if (style->TunedCount() > 0)
fFlags|=B_IS_FIXED; fFlags |= B_HAS_TUNED_FONT;
if(style->TunedCount()>0)
fFlags|=B_HAS_TUNED_FONT;
} }
} }
} }
return fFlags; return fFlags;
} }