Fixed a bunch of bugs in the font sub-system:
* BFont::Face() was almost always wrong - also on the server side, _TranslateStyleToFace() was broken. * a clean font was not correctly initialized to be_plain_font * BFont::GetFamilyAndStyle() did not work correctly if either family or style was NULL - which is allowed, and shouldn't have let it abort its task. * FontServer::GetStyle() by ID did not work reliably under certain circumstances (but those were not reached with the current server) * BFont::SetFamilyAndStyle() did not work when family was NULL, and it also never set fFace correctly. * Introduced a FontFamily::GetStyleWithFace() * Renamed some FontFamily/FontStyle methods from ie. GetID() to ID() to match the style used everywhere else in BeOS. * Removed AS_SET_FAMILY_NAME as its no longer in use. * Lots of cleanup and simplification. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14602 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
#include <String.h>
|
||||
#include <Rect.h>
|
||||
#include <Font.h>
|
||||
#include <List.h>
|
||||
#include <ObjectList.h>
|
||||
#include <Locker.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
@@ -39,9 +39,8 @@
|
||||
class FontFamily;
|
||||
class ServerFont;
|
||||
|
||||
enum font_format
|
||||
{
|
||||
FONT_TRUETYPE=0,
|
||||
enum font_format {
|
||||
FONT_TRUETYPE = 0,
|
||||
FONT_TYPE_1,
|
||||
FONT_OPENTYPE,
|
||||
FONT_BDF,
|
||||
@@ -69,8 +68,7 @@ typedef struct CachedFaceRec_
|
||||
such. Each value must be multiplied by the point size to determine size in pixels
|
||||
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
FT_Short ascent;
|
||||
FT_Short descent;
|
||||
FT_Short leading;
|
||||
@@ -85,103 +83,107 @@ typedef struct
|
||||
still offering plenty of information the style in question.
|
||||
*/
|
||||
class FontStyle : public SharedObject, public BLocker {
|
||||
public:
|
||||
public:
|
||||
FontStyle(const char* filepath,
|
||||
FT_Face face);
|
||||
virtual ~FontStyle();
|
||||
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
|
||||
*/
|
||||
inline bool IsFixedWidth() const
|
||||
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
|
||||
*/
|
||||
inline bool IsScalable() const
|
||||
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
|
||||
*/
|
||||
inline bool HasKerning() const
|
||||
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
|
||||
*/
|
||||
inline bool HasTuned() const
|
||||
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
|
||||
*/
|
||||
inline int32 TunedCount() const
|
||||
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
|
||||
*/
|
||||
inline uint16 GlyphCount() const
|
||||
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
|
||||
*/
|
||||
inline uint16 CharMapCount() const
|
||||
inline uint16 CharMapCount() const
|
||||
{ return fFTFace->num_charmaps; }
|
||||
|
||||
const char* Name() const;
|
||||
inline FontFamily* Family() const
|
||||
const char* Name() const;
|
||||
inline FontFamily* Family() const
|
||||
{ return fFontFamily; }
|
||||
inline uint16 GetID() const
|
||||
inline uint16 ID() const
|
||||
{ return fID; }
|
||||
int32 GetFlags() const;
|
||||
int32 Flags() const;
|
||||
|
||||
inline uint16 GetFace() const
|
||||
inline uint16 Face() const
|
||||
{ return fFace; }
|
||||
|
||||
const char* GetPath() const;
|
||||
font_height GetHeight(const float& size) const;
|
||||
const char* Path() const;
|
||||
font_height GetHeight(const float& size) const;
|
||||
|
||||
inline FT_Face GetFTFace() const
|
||||
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);
|
||||
|
||||
void AttachedToFamily(FontFamily* family);
|
||||
void DetachedFromFamily();
|
||||
// int16 ConvertToUnicode(uint16 c);
|
||||
|
||||
protected:
|
||||
uint16 TranslateStyleToFace(const char *name) const;
|
||||
|
||||
friend class FontFamily;
|
||||
void AttachedToFamily(FontFamily* family);
|
||||
void DetachedFromFamily();
|
||||
|
||||
FT_Face fFTFace;
|
||||
// CachedFace cachedface;
|
||||
private:
|
||||
friend class FontFamily;
|
||||
uint16 _TranslateStyleToFace(const char *name) const;
|
||||
void _SetFontFamily(FontFamily* family)
|
||||
{ fFontFamily = family; }
|
||||
void _SetID(uint16 id)
|
||||
{ fID = id; }
|
||||
|
||||
FontFamily* fFontFamily;
|
||||
private:
|
||||
FT_Face fFTFace;
|
||||
// CachedFace cachedface;
|
||||
|
||||
BString fName;
|
||||
BString fPath;
|
||||
FontFamily* fFontFamily;
|
||||
|
||||
BRect fBounds;
|
||||
BString fName;
|
||||
BString fPath;
|
||||
|
||||
uint16 fID;
|
||||
uint16 fFace;
|
||||
BRect fBounds;
|
||||
|
||||
FontStyleHeight fHeight;
|
||||
uint16 fID;
|
||||
uint16 fFace;
|
||||
|
||||
FontStyleHeight fHeight;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -192,32 +194,34 @@ protected:
|
||||
Arial Roman, Arial Italic, Arial Bold, etc.
|
||||
*/
|
||||
class FontFamily : public SharedObject {
|
||||
public:
|
||||
FontFamily(const char* namestr,
|
||||
const uint16& index);
|
||||
virtual ~FontFamily();
|
||||
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();
|
||||
|
||||
protected:
|
||||
BString fName;
|
||||
BList fStyles;
|
||||
uint16 fID;
|
||||
int32 fFlags;
|
||||
const char* Name() const;
|
||||
|
||||
bool AddStyle(FontStyle* style);
|
||||
void RemoveStyle(const char* style);
|
||||
void RemoveStyle(FontStyle* style);
|
||||
|
||||
FontStyle* GetStyle(const char* style) const;
|
||||
FontStyle* GetStyleWithFace(uint16 face) const;
|
||||
FontStyle* GetStyleWithID(uint16 face) const;
|
||||
|
||||
uint16 ID() const
|
||||
{ return fID; }
|
||||
int32 Flags();
|
||||
|
||||
bool HasStyle(const char* style) const;
|
||||
int32 CountStyles() const;
|
||||
FontStyle* StyleAt(int32 index) const;
|
||||
|
||||
protected:
|
||||
BString fName;
|
||||
BObjectList<FontStyle> fStyles;
|
||||
uint16 fID;
|
||||
int32 fFlags;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif /* FONT_FAMILY_H_ */
|
||||
|
||||
@@ -28,43 +28,43 @@ class ServerFont;
|
||||
*/
|
||||
class FontServer : public BLocker {
|
||||
public:
|
||||
FontServer(void);
|
||||
~FontServer(void);
|
||||
FontServer();
|
||||
~FontServer();
|
||||
|
||||
/*!
|
||||
\brief Determines whether the font server has started up properly
|
||||
\return true if so, false if not.
|
||||
*/
|
||||
bool IsInitialized(void) { return fInit; }
|
||||
int32 CountFamilies(void);
|
||||
bool IsInitialized() { return fInit; }
|
||||
int32 CountFamilies();
|
||||
int32 CountStyles(const char *family);
|
||||
void RemoveFamily(const char *family);
|
||||
void ScanSystemFolders(void);
|
||||
void ScanSystemFolders();
|
||||
status_t ScanDirectory(const char *path);
|
||||
void SaveList(void);
|
||||
void SaveList();
|
||||
|
||||
const char *GetFamilyName(uint16 id) const;
|
||||
const char *GetStyleName(const char *family, uint16 id) const;
|
||||
|
||||
FontStyle *GetStyle(const char *family, const char *face);
|
||||
FontStyle *GetStyle(const char *family, const char *style, uint16 face = 0);
|
||||
FontStyle *GetStyle(const char *family, uint16 id) const;
|
||||
FontStyle *GetStyle(const uint16 &familyid, const uint16 &styleid);
|
||||
FontFamily *GetFamily(const uint16 &familyid) const;
|
||||
FontStyle *GetStyle(uint16 familyID, uint16 styleID);
|
||||
FontFamily *GetFamily(uint16 familyID) const;
|
||||
FontFamily *GetFamily(const char *name) const;
|
||||
|
||||
ServerFont *GetSystemPlain(void);
|
||||
ServerFont *GetSystemBold(void);
|
||||
ServerFont *GetSystemFixed(void);
|
||||
ServerFont *GetSystemPlain();
|
||||
ServerFont *GetSystemBold();
|
||||
ServerFont *GetSystemFixed();
|
||||
|
||||
bool SetSystemPlain(const char *family, const char *style, float size);
|
||||
bool SetSystemBold(const char *family, const char *style, float size);
|
||||
bool SetSystemFixed(const char *family, const char *style, float size);
|
||||
|
||||
bool FontsNeedUpdated(void) { return fNeedUpdate; }
|
||||
bool FontsNeedUpdated() { return fNeedUpdate; }
|
||||
/*!
|
||||
\brief Called when the fonts list has been updated
|
||||
*/
|
||||
void FontsUpdated(void) { fNeedUpdate = false; }
|
||||
void FontsUpdated() { fNeedUpdate = false; }
|
||||
|
||||
protected:
|
||||
uint16 TranslateStyleToFace(const char *name) const;
|
||||
|
||||
@@ -66,16 +66,16 @@ class ServerFont {
|
||||
const char* GetStyle() const;
|
||||
const char* GetFamily() const;
|
||||
const char* GetPath() const
|
||||
{ return fStyle->GetPath(); }
|
||||
{ return fStyle->Path(); }
|
||||
|
||||
status_t SetFamilyAndStyle(uint16 familyID,
|
||||
uint16 styleID);
|
||||
status_t SetFamilyAndStyle(uint32 fontID);
|
||||
|
||||
uint16 StyleID() const
|
||||
{ return fStyle->GetID(); }
|
||||
{ return fStyle->ID(); }
|
||||
uint16 FamilyID() const
|
||||
{ return fStyle->Family()->GetID(); }
|
||||
{ return fStyle->Family()->ID(); }
|
||||
uint32 GetFamilyAndStyle() const;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user