From ef601541236eb7e08aaaf08ce3ecec96b4459788 Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Fri, 15 Mar 2013 20:48:52 +0100 Subject: [PATCH] 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. --- src/apps/terminal/PrefHandler.cpp | 35 ++++++++++++++++++------------- src/apps/terminal/PrefHandler.h | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/apps/terminal/PrefHandler.cpp b/src/apps/terminal/PrefHandler.cpp index 3f75d18cd4..d897b9db76 100644 --- a/src/apps/terminal/PrefHandler.cpp +++ b/src/apps/terminal/PrefHandler.cpp @@ -105,7 +105,7 @@ PrefHandler::PrefHandler() GetDefaultPath(path); OpenText(path.Path()); - _ConfirmFont(PREF_HALF_FONT_FAMILY, be_fixed_font); + _ConfirmFont(be_fixed_font); } @@ -377,29 +377,34 @@ PrefHandler::IsEmpty() const 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_style style; - for (int32 i = 0; i < count; i++) { - if (get_font_family(i, &family) != B_OK) + const char *prefFamily = getString(PREF_HALF_FONT_FAMILY); + 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; - if (strcmp(family, font) == 0) { - // found font family: we can safely use this font - return; + const char *prefStyle = getString(PREF_HALF_FONT_STYLE); + int32 stylesCount = (prefStyle != NULL) ? count_font_styles(family) : 0; + + 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 - - fallback->GetFamilyAndStyle(&family, NULL); - setString(key, family); + fallbackFont->GetFamilyAndStyle(&family, &style); + setString(PREF_HALF_FONT_FAMILY, family); + setString(PREF_HALF_FONT_STYLE, style); } diff --git a/src/apps/terminal/PrefHandler.h b/src/apps/terminal/PrefHandler.h index 83c565dc45..55014c23ea 100644 --- a/src/apps/terminal/PrefHandler.h +++ b/src/apps/terminal/PrefHandler.h @@ -72,7 +72,7 @@ class PrefHandler { static status_t GetDefaultPath(BPath& path); private: - void _ConfirmFont(const char *key, const BFont *fallback); + void _ConfirmFont(const BFont *fallbackFont); status_t _LoadFromDefault(const pref_defaults* defaults = NULL); status_t _LoadFromTextFile(const char * path);