Handle font style on loading default Terminal preferences

Fix the PrefHandler::_ConfirmFont to take into account not only the
font family but the font style too. This improves the popup menu
checkmark synchronization in the Preferences View. This problem can
be reproduced on very first start of application without previously
stored Terminal settings. Default family/style for this case is
currently defined as "Courier 19BT"/"Regular" but default fixed
font has correspondently "DejaVu Sans Mono"/"Book". Previous version
of _ConfirmFont() process only the family and left the style in default
"Regular" one. So opening Preferences View and attempting to set the
checkmark on corresponding family/style menuitem was usually failed.
This commit is contained in:
Siarzhuk Zharski 2013-03-15 20:48:52 +01:00
parent d58ff0b187
commit ef60154123
2 changed files with 21 additions and 16 deletions

View File

@ -105,7 +105,7 @@ PrefHandler::PrefHandler()
GetDefaultPath(path); GetDefaultPath(path);
OpenText(path.Path()); OpenText(path.Path());
_ConfirmFont(PREF_HALF_FONT_FAMILY, be_fixed_font); _ConfirmFont(be_fixed_font);
} }
@ -377,29 +377,34 @@ PrefHandler::IsEmpty() const
void void
PrefHandler::_ConfirmFont(const char *key, const BFont *fallback) PrefHandler::_ConfirmFont(const BFont *fallbackFont)
{ {
int32 count = count_font_families();
const char *font = getString(key);
if (font == NULL)
count = 0;
font_family family; font_family family;
font_style style;
for (int32 i = 0; i < count; i++) { const char *prefFamily = getString(PREF_HALF_FONT_FAMILY);
if (get_font_family(i, &family) != B_OK) int32 familiesCount = (prefFamily != NULL) ? count_font_families() : 0;
for (int32 i = 0; i < familiesCount; i++) {
if (get_font_family(i, &family) != B_OK
|| strcmp(family, prefFamily) != 0)
continue; continue;
if (strcmp(family, font) == 0) { const char *prefStyle = getString(PREF_HALF_FONT_STYLE);
// found font family: we can safely use this font int32 stylesCount = (prefStyle != NULL) ? count_font_styles(family) : 0;
return;
for (int32 j = 0; j < stylesCount; j++) {
// check style if we can safely use this font
if (get_font_style(family, j, &style) == B_OK
&& strcmp(style, prefStyle) == 0)
return;
} }
} }
// use fall-back font // use fall-back font
fallbackFont->GetFamilyAndStyle(&family, &style);
fallback->GetFamilyAndStyle(&family, NULL); setString(PREF_HALF_FONT_FAMILY, family);
setString(key, family); setString(PREF_HALF_FONT_STYLE, style);
} }

View File

@ -72,7 +72,7 @@ class PrefHandler {
static status_t GetDefaultPath(BPath& path); static status_t GetDefaultPath(BPath& path);
private: private:
void _ConfirmFont(const char *key, const BFont *fallback); void _ConfirmFont(const BFont *fallbackFont);
status_t _LoadFromDefault(const pref_defaults* defaults = NULL); status_t _LoadFromDefault(const pref_defaults* defaults = NULL);
status_t _LoadFromTextFile(const char * path); status_t _LoadFromTextFile(const char * path);