Font.cpp: Style cleanup
* Unify asterisk style * switch indentation style of FontList declaration * Order FontList methods according to declaration * Use named constants in default BFont constructor for spacing and encoding.
This commit is contained in:
+100
-92
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2008, Haiku, Inc.
|
||||
* Copyright 2001-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -63,15 +63,17 @@ namespace {
|
||||
class FontList : public BLocker {
|
||||
public:
|
||||
FontList();
|
||||
~FontList();
|
||||
virtual ~FontList();
|
||||
|
||||
static FontList* Default();
|
||||
|
||||
bool UpdatedOnServer();
|
||||
|
||||
status_t FamilyAt(int32 index, font_family *_family, uint32 *_flags);
|
||||
status_t StyleAt(font_family family, int32 index, font_style *_style,
|
||||
uint16 *_face, uint32 *_flags);
|
||||
status_t FamilyAt(int32 index, font_family* _family,
|
||||
uint32* _flags);
|
||||
status_t StyleAt(font_family family, int32 index,
|
||||
font_style* _style, uint16* _face,
|
||||
uint32* _flags);
|
||||
|
||||
int32 CountFamilies();
|
||||
int32 CountStyles(font_family family);
|
||||
@@ -83,6 +85,7 @@ class FontList : public BLocker {
|
||||
family* _FindFamily(font_family name);
|
||||
static void _InitSingleton();
|
||||
|
||||
private:
|
||||
BObjectList<family> fFamilies;
|
||||
family* fLastFamily;
|
||||
bigtime_t fLastUpdate;
|
||||
@@ -142,20 +145,75 @@ FontList::UpdatedOnServer()
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FontList::_RevisionOnServer()
|
||||
status_t
|
||||
FontList::FamilyAt(int32 index, font_family* _family, uint32* _flags)
|
||||
{
|
||||
BPrivate::AppServerLink link;
|
||||
link.StartMessage(AS_GET_FONT_LIST_REVISION);
|
||||
BAutolock locker(this);
|
||||
|
||||
int32 code;
|
||||
if (link.FlushWithReply(code) != B_OK || code != B_OK)
|
||||
return B_ERROR;
|
||||
status_t status = _UpdateIfNecessary();
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
int32 revision;
|
||||
link.Read<int32>(&revision);
|
||||
::family* family = fFamilies.ItemAt(index);
|
||||
if (family == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
return revision;
|
||||
memcpy(*_family, family->name.String(), family->name.Length() + 1);
|
||||
if (_flags)
|
||||
*_flags = family->flags;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
FontList::StyleAt(font_family familyName, int32 index, font_style* _style,
|
||||
uint16* _face, uint32* _flags)
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
status_t status = _UpdateIfNecessary();
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
::family* family = _FindFamily(familyName);
|
||||
if (family == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
::style* style = family->styles.ItemAt(index);
|
||||
if (style == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
memcpy(*_style, style->name.String(), style->name.Length() + 1);
|
||||
if (_face)
|
||||
*_face = style->face;
|
||||
if (_flags)
|
||||
*_flags = style->flags;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FontList::CountFamilies()
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
_UpdateIfNecessary();
|
||||
return fFamilies.CountItems();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FontList::CountStyles(font_family familyName)
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
_UpdateIfNecessary();
|
||||
|
||||
::family* family = _FindFamily(familyName);
|
||||
if (family == NULL)
|
||||
return 0;
|
||||
|
||||
return family->styles.CountItems();
|
||||
}
|
||||
|
||||
|
||||
@@ -233,6 +291,23 @@ FontList::_UpdateIfNecessary()
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FontList::_RevisionOnServer()
|
||||
{
|
||||
BPrivate::AppServerLink link;
|
||||
link.StartMessage(AS_GET_FONT_LIST_REVISION);
|
||||
|
||||
int32 code;
|
||||
if (link.FlushWithReply(code) != B_OK || code != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
int32 revision;
|
||||
link.Read<int32>(&revision);
|
||||
|
||||
return revision;
|
||||
}
|
||||
|
||||
|
||||
family*
|
||||
FontList::_FindFamily(font_family name)
|
||||
{
|
||||
@@ -247,78 +322,6 @@ FontList::_FindFamily(font_family name)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
FontList::FamilyAt(int32 index, font_family *_family, uint32 *_flags)
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
status_t status = _UpdateIfNecessary();
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
::family* family = fFamilies.ItemAt(index);
|
||||
if (family == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
memcpy(*_family, family->name.String(), family->name.Length() + 1);
|
||||
if (_flags)
|
||||
*_flags = family->flags;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
FontList::StyleAt(font_family familyName, int32 index, font_style *_style,
|
||||
uint16 *_face, uint32 *_flags)
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
status_t status = _UpdateIfNecessary();
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
::family* family = _FindFamily(familyName);
|
||||
if (family == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
::style* style = family->styles.ItemAt(index);
|
||||
if (style == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
memcpy(*_style, style->name.String(), style->name.Length() + 1);
|
||||
if (_face)
|
||||
*_face = style->face;
|
||||
if (_flags)
|
||||
*_flags = style->flags;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FontList::CountFamilies()
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
_UpdateIfNecessary();
|
||||
return fFamilies.CountItems();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FontList::CountStyles(font_family familyName)
|
||||
{
|
||||
BAutolock locker(this);
|
||||
|
||||
_UpdateIfNecessary();
|
||||
|
||||
::family* family = _FindFamily(familyName);
|
||||
if (family == NULL)
|
||||
return 0;
|
||||
|
||||
return family->styles.CountItems();
|
||||
}
|
||||
|
||||
|
||||
/*static*/ void
|
||||
FontList::_InitSingleton()
|
||||
{
|
||||
@@ -369,16 +372,21 @@ _init_global_fonts_()
|
||||
}
|
||||
|
||||
|
||||
void _font_control_(BFont *font, int32 cmd, void *data)
|
||||
void
|
||||
_font_control_(BFont* font, int32 cmd, void* data)
|
||||
{
|
||||
}
|
||||
|
||||
status_t get_font_cache_info(uint32 id, void *set)
|
||||
|
||||
status_t
|
||||
get_font_cache_info(uint32 id, void* set)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t set_font_cache_info(uint32 id, void *set)
|
||||
|
||||
status_t
|
||||
set_font_cache_info(uint32 id, void* set)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
@@ -495,8 +503,8 @@ BFont::BFont()
|
||||
fShear(90.0),
|
||||
fRotation(0.0),
|
||||
fFalseBoldWidth(0.0),
|
||||
fSpacing(0),
|
||||
fEncoding(0),
|
||||
fSpacing(B_CHAR_SPACING),
|
||||
fEncoding(B_UNICODE_UTF8),
|
||||
fFace(0),
|
||||
fFlags(0),
|
||||
fExtraFlags(kUninitializedExtraFlags)
|
||||
|
||||
Reference in New Issue
Block a user