From 831a01f893aeeebf592e19494fac569e2d516d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 10 Nov 2005 15:48:37 +0000 Subject: [PATCH] FontStyles are now also orded, but not alphabetically: their faces determine the order, regular fonts come first, then bold, and then italics. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14828 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/FontFamily.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/servers/app/FontFamily.cpp b/src/servers/app/FontFamily.cpp index cc8a8a6a40..a2fb967760 100644 --- a/src/servers/app/FontFamily.cpp +++ b/src/servers/app/FontFamily.cpp @@ -22,6 +22,34 @@ const uint32 kInvalidFamilyFlags = ~0UL; +static int +font_score(const FontStyle* style) +{ + int score = 0; + if (style->Face() & B_REGULAR_FACE) + score += 10; + else { + if (style->Face() & B_BOLD_FACE) + score += 5; + if (style->Face() & B_ITALIC_FACE) + score--; + } + + return score; +} + + +static int +compare_font_styles(const FontStyle* a, const FontStyle* b) +{ + // Regular fonts come first, then bold, then italics + return font_score(b) - font_score(a); +} + + +// #pragma mark - + + /*! \brief Constructor \param filepath path to a font file @@ -277,8 +305,10 @@ FontFamily::AddStyle(FontStyle *style) return false; } + if (!fStyles.BinaryInsert(style, compare_font_styles)) + return false; + style->_SetFontFamily(this, fNextID++); - fStyles.AddItem(style); // force a refresh if a request for font flags is needed fFlags = kInvalidFamilyFlags;