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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -63,15 +63,17 @@ namespace {
|
|||||||
class FontList : public BLocker {
|
class FontList : public BLocker {
|
||||||
public:
|
public:
|
||||||
FontList();
|
FontList();
|
||||||
~FontList();
|
virtual ~FontList();
|
||||||
|
|
||||||
static FontList* Default();
|
static FontList* Default();
|
||||||
|
|
||||||
bool UpdatedOnServer();
|
bool UpdatedOnServer();
|
||||||
|
|
||||||
status_t FamilyAt(int32 index, font_family *_family, uint32 *_flags);
|
status_t FamilyAt(int32 index, font_family* _family,
|
||||||
status_t StyleAt(font_family family, int32 index, font_style *_style,
|
uint32* _flags);
|
||||||
uint16 *_face, uint32 *_flags);
|
status_t StyleAt(font_family family, int32 index,
|
||||||
|
font_style* _style, uint16* _face,
|
||||||
|
uint32* _flags);
|
||||||
|
|
||||||
int32 CountFamilies();
|
int32 CountFamilies();
|
||||||
int32 CountStyles(font_family family);
|
int32 CountStyles(font_family family);
|
||||||
@@ -83,6 +85,7 @@ class FontList : public BLocker {
|
|||||||
family* _FindFamily(font_family name);
|
family* _FindFamily(font_family name);
|
||||||
static void _InitSingleton();
|
static void _InitSingleton();
|
||||||
|
|
||||||
|
private:
|
||||||
BObjectList<family> fFamilies;
|
BObjectList<family> fFamilies;
|
||||||
family* fLastFamily;
|
family* fLastFamily;
|
||||||
bigtime_t fLastUpdate;
|
bigtime_t fLastUpdate;
|
||||||
@@ -142,20 +145,75 @@ FontList::UpdatedOnServer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
status_t
|
||||||
FontList::_RevisionOnServer()
|
FontList::FamilyAt(int32 index, font_family* _family, uint32* _flags)
|
||||||
{
|
{
|
||||||
BPrivate::AppServerLink link;
|
BAutolock locker(this);
|
||||||
link.StartMessage(AS_GET_FONT_LIST_REVISION);
|
|
||||||
|
|
||||||
int32 code;
|
status_t status = _UpdateIfNecessary();
|
||||||
if (link.FlushWithReply(code) != B_OK || code != B_OK)
|
if (status < B_OK)
|
||||||
return B_ERROR;
|
return status;
|
||||||
|
|
||||||
int32 revision;
|
::family* family = fFamilies.ItemAt(index);
|
||||||
link.Read<int32>(&revision);
|
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*
|
family*
|
||||||
FontList::_FindFamily(font_family name)
|
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
|
/*static*/ void
|
||||||
FontList::_InitSingleton()
|
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;
|
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;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -495,8 +503,8 @@ BFont::BFont()
|
|||||||
fShear(90.0),
|
fShear(90.0),
|
||||||
fRotation(0.0),
|
fRotation(0.0),
|
||||||
fFalseBoldWidth(0.0),
|
fFalseBoldWidth(0.0),
|
||||||
fSpacing(0),
|
fSpacing(B_CHAR_SPACING),
|
||||||
fEncoding(0),
|
fEncoding(B_UNICODE_UTF8),
|
||||||
fFace(0),
|
fFace(0),
|
||||||
fFlags(0),
|
fFlags(0),
|
||||||
fExtraFlags(kUninitializedExtraFlags)
|
fExtraFlags(kUninitializedExtraFlags)
|
||||||
|
|||||||
Reference in New Issue
Block a user