The font manager now has default fonts for bold/fixed as well - these are now used

in the DesktopSettings as defaults, too (but can be changed there).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14804 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-11-09 19:16:25 +00:00
parent 16f782ccbd
commit 974dd00c85
5 changed files with 74 additions and 55 deletions

View File

@ -56,7 +56,9 @@ class FontManager : public BLooper {
FontStyle *GetStyle(uint16 familyID, uint16 styleID) const;
FontStyle* FindStyleMatchingFace(uint16 face) const;
const ServerFont* DefaultFont() const;
const ServerFont* DefaultPlainFont() const;
const ServerFont* DefaultBoldFont() const;
const ServerFont* DefaultFixedFont() const;
void AttachUser(uid_t userID);
void DetachUser(uid_t userID);
@ -66,7 +68,10 @@ class FontManager : public BLooper {
struct font_mapping;
bool _LoadRecentFontMappings();
status_t _SetDefaultFont();
FontStyle* _GetDefaultStyle(const char *familyName, const char *styleName,
const char *fallbackFamily, const char *fallbackStyle,
uint16 fallbackFace);
status_t _SetDefaultFonts();
void _AddSystemPaths();
status_t _AddPath(const char* path);
status_t _AddPath(BEntry& entry, font_directory** _newDirectory = NULL);
@ -87,7 +92,9 @@ class FontManager : public BLooper {
BObjectList<font_mapping> fMappings;
BObjectList<FontFamily> fFamilies;
HashTable fStyleHashTable;
ServerFont *fDefaultFont;
ServerFont* fDefaultPlainFont;
ServerFont* fDefaultBoldFont;
ServerFont* fDefaultFixedFont;
bool fScanned;
int32 fNextID;
};

View File

@ -32,16 +32,9 @@ DesktopSettings::Private::~Private()
void
DesktopSettings::Private::_SetDefaults()
{
_SetFont(fPlainFont, DEFAULT_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE, FALLBACK_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE,
B_REGULAR_FACE);
_SetFont(fBoldFont, DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE, FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
B_BOLD_FACE);
_SetFont(fFixedFont, DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE, FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
B_REGULAR_FACE);
fFixedFont.SetSpacing(B_FIXED_SPACING);
fPlainFont = *gFontManager->DefaultPlainFont();
fBoldFont = *gFontManager->DefaultBoldFont();
fFixedFont = *gFontManager->DefaultFixedFont();
fMouseMode = B_NORMAL_MOUSE;
@ -67,28 +60,6 @@ DesktopSettings::Private::_SetDefaults()
}
void
DesktopSettings::Private::_SetFont(ServerFont &font, const char *familyName,
const char *styleName, float size, const char *fallbackFamily,
const char *fallbackStyle, uint16 fallbackFace)
{
BAutolock locker(gFontManager);
// try to find a matching font
FontStyle* style = gFontManager->GetStyle(familyName, styleName);
if (style == NULL) {
style = gFontManager->GetStyle(fallbackFamily, fallbackStyle);
if (style == NULL) {
style = gFontManager->FindStyleMatchingFace(fallbackFace);
}
}
if (style != NULL)
font.SetStyle(*style);
}
status_t
DesktopSettings::Private::_Load()
{

View File

@ -49,9 +49,6 @@ class DesktopSettings::Private : public BLocker {
private:
void _SetDefaults();
void _SetFont(ServerFont& font, const char* family, const char* style,
float size, const char *fallbackFamily,
const char* fallbackStyle, uint16 fallbackFace);
status_t _Load();
ServerFont fPlainFont;

View File

@ -58,7 +58,6 @@ struct FontManager::font_mapping {
FontManager::FontManager()
: BLooper("Font Manager"),
fFamilies(20),
fDefaultFont(NULL),
fScanned(false),
fNextID(0)
{
@ -68,7 +67,7 @@ FontManager::FontManager()
_AddSystemPaths();
_LoadRecentFontMappings();
fInitStatus = _SetDefaultFont();
fInitStatus = _SetDefaultFonts();
}
/*
@ -141,30 +140,61 @@ FontManager::_RemoveFamily(const char *familyName)
}
/*!
\brief Sets the font that will be used when you create an empty
ServerFont without specifying a style.
*/
status_t
FontManager::_SetDefaultFont()
FontStyle*
FontManager::_GetDefaultStyle(const char *familyName, const char *styleName,
const char *fallbackFamily, const char *fallbackStyle,
uint16 fallbackFace)
{
FontStyle* style = GetStyle(DEFAULT_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE);
// try to find a matching font
FontStyle* style = GetStyle(familyName, styleName);
if (style == NULL) {
style = GetStyle(FALLBACK_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE);
style = GetStyle(fallbackFamily, fallbackStyle);
if (style == NULL) {
style = FindStyleMatchingFace(B_REGULAR_FACE);
if (style == NULL && fFamilies.CountItems() != 0)
style = FindStyleMatchingFace(fallbackFace);
if (style == NULL && FamilyAt(0) != NULL)
style = FamilyAt(0)->StyleAt(0);
}
}
return style;
}
/*!
\brief Sets the fonts that will be used when you create an empty
ServerFont without specifying a style, as well as the default
Desktop fonts if there are no settings available.
*/
status_t
FontManager::_SetDefaultFonts()
{
FontStyle* style = _GetDefaultStyle(DEFAULT_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE, FALLBACK_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE,
B_REGULAR_FACE);
if (style == NULL)
return B_ERROR;
fDefaultFont = new (nothrow) ServerFont(*style, DEFAULT_PLAIN_FONT_SIZE);
if (fDefaultFont == NULL)
fDefaultPlainFont = new (nothrow) ServerFont(*style, DEFAULT_PLAIN_FONT_SIZE);
if (fDefaultPlainFont == NULL)
return B_NO_MEMORY;
style = _GetDefaultStyle(DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, B_BOLD_FACE);
fDefaultBoldFont = new (nothrow) ServerFont(*style, DEFAULT_BOLD_FONT_SIZE);
if (fDefaultBoldFont == NULL)
return B_NO_MEMORY;
style = _GetDefaultStyle(DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, B_REGULAR_FACE);
fDefaultFixedFont = new (nothrow) ServerFont(*style, DEFAULT_FIXED_FONT_SIZE);
if (fDefaultFixedFont == NULL)
return B_NO_MEMORY;
fDefaultFixedFont->SetSpacing(B_FIXED_SPACING);
return B_OK;
}
@ -631,9 +661,23 @@ FontManager::FindStyleMatchingFace(uint16 face) const
const ServerFont*
FontManager::DefaultFont() const
FontManager::DefaultPlainFont() const
{
return fDefaultFont;
return fDefaultPlainFont;
}
const ServerFont*
FontManager::DefaultBoldFont() const
{
return fDefaultBoldFont;
}
const ServerFont*
FontManager::DefaultFixedFont() const
{
return fDefaultFixedFont;
}

View File

@ -147,7 +147,7 @@ ServerFont::ServerFont()
:
fStyle(NULL)
{
*this = *gFontManager->DefaultFont();
*this = *gFontManager->DefaultPlainFont();
}