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:
+154
-146
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2008, Haiku, Inc.
|
||||
* Copyright 2001-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -41,9 +41,9 @@ static BFont sPlainFont;
|
||||
static BFont sBoldFont;
|
||||
static BFont sFixedFont;
|
||||
|
||||
const BFont *be_plain_font = &sPlainFont;
|
||||
const BFont *be_bold_font = &sBoldFont;
|
||||
const BFont *be_fixed_font = &sFixedFont;
|
||||
const BFont* be_plain_font = &sPlainFont;
|
||||
const BFont* be_bold_font = &sBoldFont;
|
||||
const BFont* be_fixed_font = &sFixedFont;
|
||||
|
||||
|
||||
struct style {
|
||||
@@ -61,35 +61,38 @@ struct family {
|
||||
namespace {
|
||||
|
||||
class FontList : public BLocker {
|
||||
public:
|
||||
FontList();
|
||||
~FontList();
|
||||
public:
|
||||
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 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);
|
||||
int32 CountFamilies();
|
||||
int32 CountStyles(font_family family);
|
||||
|
||||
private:
|
||||
status_t _UpdateIfNecessary();
|
||||
status_t _Update();
|
||||
int32 _RevisionOnServer();
|
||||
family* _FindFamily(font_family name);
|
||||
static void _InitSingleton();
|
||||
private:
|
||||
status_t _UpdateIfNecessary();
|
||||
status_t _Update();
|
||||
int32 _RevisionOnServer();
|
||||
family* _FindFamily(font_family name);
|
||||
static void _InitSingleton();
|
||||
|
||||
BObjectList<family> fFamilies;
|
||||
family* fLastFamily;
|
||||
bigtime_t fLastUpdate;
|
||||
int32 fRevision;
|
||||
private:
|
||||
BObjectList<family> fFamilies;
|
||||
family* fLastFamily;
|
||||
bigtime_t fLastUpdate;
|
||||
int32 fRevision;
|
||||
|
||||
static pthread_once_t sDefaultInitOnce;
|
||||
static FontList* sDefaultInstance;
|
||||
static pthread_once_t sDefaultInitOnce;
|
||||
static FontList* sDefaultInstance;
|
||||
};
|
||||
|
||||
pthread_once_t FontList::sDefaultInitOnce = PTHREAD_ONCE_INIT;
|
||||
@@ -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()
|
||||
{
|
||||
@@ -348,7 +351,7 @@ _init_global_fonts_()
|
||||
|
||||
while (link.ReadString(type, sizeof(type)) >= B_OK && type[0]) {
|
||||
BFont dummy;
|
||||
BFont *font = &dummy;
|
||||
BFont* font = &dummy;
|
||||
|
||||
if (!strcmp(type, "plain"))
|
||||
font = &sPlainFont;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -386,7 +394,7 @@ status_t set_font_cache_info(uint32 id, void *set)
|
||||
|
||||
// Private function used to replace the R5 hack which sets a system font
|
||||
void
|
||||
_set_system_font_(const char *which, font_family family, font_style style,
|
||||
_set_system_font_(const char* which, font_family family, font_style style,
|
||||
float size)
|
||||
{
|
||||
// R5 used a global area offset table to set the system fonts in the Font
|
||||
@@ -441,7 +449,7 @@ count_font_styles(font_family family)
|
||||
|
||||
// Retrieves the family name at the specified index
|
||||
status_t
|
||||
get_font_family(int32 index, font_family *_name, uint32 *_flags)
|
||||
get_font_family(int32 index, font_family* _name, uint32* _flags)
|
||||
{
|
||||
if (_name == NULL)
|
||||
return B_BAD_VALUE;
|
||||
@@ -452,8 +460,8 @@ get_font_family(int32 index, font_family *_name, uint32 *_flags)
|
||||
|
||||
// Retrieves the family name at the specified index
|
||||
status_t
|
||||
get_font_style(font_family family, int32 index, font_style *_name,
|
||||
uint32 *_flags)
|
||||
get_font_style(font_family family, int32 index, font_style* _name,
|
||||
uint32* _flags)
|
||||
{
|
||||
return get_font_style(family, index, _name, NULL, _flags);
|
||||
}
|
||||
@@ -461,8 +469,8 @@ get_font_style(font_family family, int32 index, font_style *_name,
|
||||
|
||||
// Retrieves the family name at the specified index
|
||||
status_t
|
||||
get_font_style(font_family family, int32 index, font_style *_name,
|
||||
uint16 *_face, uint32 *_flags)
|
||||
get_font_style(font_family family, int32 index, font_style* _name,
|
||||
uint16* _face, uint32* _flags)
|
||||
{
|
||||
// The face value returned by this function is not very reliable. At the
|
||||
// same time, the value returned should be fairly reliable, returning the
|
||||
@@ -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)
|
||||
@@ -511,13 +519,13 @@ BFont::BFont()
|
||||
}
|
||||
|
||||
|
||||
BFont::BFont(const BFont &font)
|
||||
BFont::BFont(const BFont& font)
|
||||
{
|
||||
*this = font;
|
||||
}
|
||||
|
||||
|
||||
BFont::BFont(const BFont *font)
|
||||
BFont::BFont(const BFont* font)
|
||||
{
|
||||
if (font != NULL)
|
||||
*this = *font;
|
||||
@@ -684,7 +692,7 @@ BFont::SetFlags(uint32 flags)
|
||||
|
||||
|
||||
void
|
||||
BFont::GetFamilyAndStyle(font_family *family, font_style *style) const
|
||||
BFont::GetFamilyAndStyle(font_family* family, font_style* style) const
|
||||
{
|
||||
if (family == NULL && style == NULL)
|
||||
return;
|
||||
@@ -878,7 +886,7 @@ BFont::CountTuned() const
|
||||
|
||||
|
||||
void
|
||||
BFont::GetTunedInfo(int32 index, tuned_font_info *info) const
|
||||
BFont::GetTunedInfo(int32 index, tuned_font_info* info) const
|
||||
{
|
||||
if (info == NULL)
|
||||
return;
|
||||
@@ -898,18 +906,18 @@ BFont::GetTunedInfo(int32 index, tuned_font_info *info) const
|
||||
|
||||
|
||||
void
|
||||
BFont::TruncateString(BString *inOut, uint32 mode, float width) const
|
||||
BFont::TruncateString(BString* inOut, uint32 mode, float width) const
|
||||
{
|
||||
// NOTE: Careful, we cannot directly use "inOut->String()" as result
|
||||
// array, because the string length increases by 3 bytes in the worst
|
||||
// case scenario.
|
||||
const char *string = inOut->String();
|
||||
const char* string = inOut->String();
|
||||
GetTruncatedStrings(&string, 1, mode, width, inOut);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||
BFont::GetTruncatedStrings(const char* stringArray[], int32 numStrings,
|
||||
uint32 mode, float width, BString resultArray[]) const
|
||||
{
|
||||
if (stringArray != NULL && numStrings > 0) {
|
||||
@@ -921,7 +929,7 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||
int32 numChars = resultArray[i].CountChars();
|
||||
|
||||
// get the escapement of each glyph in font units
|
||||
float *escapementArray = new float[numChars];
|
||||
float* escapementArray = new float[numChars];
|
||||
GetEscapements(stringArray[i], numChars, NULL, escapementArray);
|
||||
|
||||
truncate_string(resultArray[i], mode, width, escapementArray,
|
||||
@@ -934,12 +942,12 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||
|
||||
|
||||
void
|
||||
BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||
uint32 mode, float width, char *resultArray[]) const
|
||||
BFont::GetTruncatedStrings(const char* stringArray[], int32 numStrings,
|
||||
uint32 mode, float width, char* resultArray[]) const
|
||||
{
|
||||
if (stringArray != NULL && numStrings > 0) {
|
||||
for (int32 i = 0; i < numStrings; i++) {
|
||||
BString *strings = new BString[numStrings];
|
||||
BString* strings = new BString[numStrings];
|
||||
GetTruncatedStrings(stringArray, numStrings, mode, width, strings);
|
||||
|
||||
for (int32 i = 0; i < numStrings; i++)
|
||||
@@ -952,7 +960,7 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||
|
||||
|
||||
float
|
||||
BFont::StringWidth(const char *string) const
|
||||
BFont::StringWidth(const char* string) const
|
||||
{
|
||||
if (string == NULL)
|
||||
return 0.0;
|
||||
@@ -966,7 +974,7 @@ BFont::StringWidth(const char *string) const
|
||||
|
||||
|
||||
float
|
||||
BFont::StringWidth(const char *string, int32 length) const
|
||||
BFont::StringWidth(const char* string, int32 length) const
|
||||
{
|
||||
if (!string || length < 1)
|
||||
return 0.0f;
|
||||
@@ -979,7 +987,7 @@ BFont::StringWidth(const char *string, int32 length) const
|
||||
|
||||
|
||||
void
|
||||
BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[],
|
||||
BFont::GetStringWidths(const char* stringArray[], const int32 lengthArray[],
|
||||
int32 numStrings, float widthArray[]) const
|
||||
{
|
||||
if (stringArray == NULL || lengthArray == NULL || numStrings < 1
|
||||
@@ -1019,7 +1027,7 @@ BFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
|
||||
void
|
||||
BFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
escapement_delta *delta, float escapementArray[]) const
|
||||
escapement_delta* delta, float escapementArray[]) const
|
||||
{
|
||||
if (charArray == NULL || numChars < 1 || escapementArray == NULL)
|
||||
return;
|
||||
@@ -1052,7 +1060,7 @@ BFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
|
||||
void
|
||||
BFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
escapement_delta *delta, BPoint escapementArray[]) const
|
||||
escapement_delta* delta, BPoint escapementArray[]) const
|
||||
{
|
||||
GetEscapements(charArray, numChars, delta, escapementArray, NULL);
|
||||
}
|
||||
@@ -1060,7 +1068,7 @@ BFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
|
||||
void
|
||||
BFont::GetEscapements(const char charArray[], int32 numChars,
|
||||
escapement_delta *delta, BPoint escapementArray[],
|
||||
escapement_delta* delta, BPoint escapementArray[],
|
||||
BPoint offsetArray[]) const
|
||||
{
|
||||
if (charArray == NULL || numChars < 1 || escapementArray == NULL)
|
||||
@@ -1122,7 +1130,7 @@ BFont::GetEdges(const char charArray[], int32 numChars,
|
||||
|
||||
|
||||
void
|
||||
BFont::GetHeight(font_height *_height) const
|
||||
BFont::GetHeight(font_height* _height) const
|
||||
{
|
||||
if (_height == NULL)
|
||||
return;
|
||||
@@ -1161,7 +1169,7 @@ BFont::GetBoundingBoxesAsGlyphs(const char charArray[], int32 numChars,
|
||||
|
||||
void
|
||||
BFont::GetBoundingBoxesAsString(const char charArray[], int32 numChars,
|
||||
font_metric_mode mode, escapement_delta *delta,
|
||||
font_metric_mode mode, escapement_delta* delta,
|
||||
BRect boundingBoxArray[]) const
|
||||
{
|
||||
_GetBoundingBoxes(charArray, numChars, mode, true, delta,
|
||||
@@ -1171,7 +1179,7 @@ BFont::GetBoundingBoxesAsString(const char charArray[], int32 numChars,
|
||||
|
||||
void
|
||||
BFont::_GetBoundingBoxes(const char charArray[], int32 numChars,
|
||||
font_metric_mode mode, bool string_escapement, escapement_delta *delta,
|
||||
font_metric_mode mode, bool string_escapement, escapement_delta* delta,
|
||||
BRect boundingBoxArray[], bool asString) const
|
||||
{
|
||||
if (charArray == NULL || numChars < 1 || boundingBoxArray == NULL)
|
||||
@@ -1214,7 +1222,7 @@ BFont::_GetBoundingBoxes(const char charArray[], int32 numChars,
|
||||
|
||||
|
||||
void
|
||||
BFont::GetBoundingBoxesForStrings(const char *stringArray[], int32 numStrings,
|
||||
BFont::GetBoundingBoxesForStrings(const char* stringArray[], int32 numStrings,
|
||||
font_metric_mode mode, escapement_delta deltas[],
|
||||
BRect boundingBoxArray[]) const
|
||||
{
|
||||
@@ -1259,7 +1267,7 @@ BFont::GetBoundingBoxesForStrings(const char *stringArray[], int32 numStrings,
|
||||
|
||||
void
|
||||
BFont::GetGlyphShapes(const char charArray[], int32 numChars,
|
||||
BShape *glyphShapeArray[]) const
|
||||
BShape* glyphShapeArray[]) const
|
||||
{
|
||||
// TODO: implement code specifically for passing BShapes to and
|
||||
// from the server
|
||||
@@ -1317,8 +1325,8 @@ BFont::GetHasGlyphs(const char charArray[], int32 numChars,
|
||||
}
|
||||
|
||||
|
||||
BFont &
|
||||
BFont::operator=(const BFont &font)
|
||||
BFont&
|
||||
BFont::operator=(const BFont& font)
|
||||
{
|
||||
fFamilyID = font.fFamilyID;
|
||||
fStyleID = font.fStyleID;
|
||||
@@ -1338,7 +1346,7 @@ BFont::operator=(const BFont &font)
|
||||
|
||||
|
||||
bool
|
||||
BFont::operator==(const BFont &font) const
|
||||
BFont::operator==(const BFont& font) const
|
||||
{
|
||||
return fFamilyID == font.fFamilyID
|
||||
&& fStyleID == font.fStyleID
|
||||
@@ -1353,7 +1361,7 @@ BFont::operator==(const BFont &font) const
|
||||
|
||||
|
||||
bool
|
||||
BFont::operator!=(const BFont &font) const
|
||||
BFont::operator!=(const BFont& font) const
|
||||
{
|
||||
return fFamilyID != font.fFamilyID
|
||||
|| fStyleID != font.fStyleID
|
||||
|
||||
Reference in New Issue
Block a user