From 9aca3096119a35fe3ae7dff4a8ef55f4dac5d7ef Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 27 Aug 2014 06:00:10 -0700 Subject: [PATCH] Default font: more fine tuning In order to get rid of the old default font on Windows (Calibri) we are going to near ridiculous length. The reason for this is that we in the past always saved the default font in the settings (how stupid was that!) and so now even with a new default font in place, since there is an explicit font in the settings we take that instead of the default. Instead of requiring our existing users to use a registry cleaner to get the correct default font on Windows 7 and later (the VAST majority of our Windows users at this stage), we simply explicitly ignore that old default font. There is one very nasty side effect. A user cannot set Calibri as their font of choice on Windows 7 or later (because we always force them back onto Segoe). Given how much nicer Segoe looks I think this is an acceptable flaw - let's hope this doesn't come back to bite me in the future. At the same time this changes the default font size handling. We try to get the default font size of the OS so the app looks "right". This seems to not give me the expected result on Linux with KDE, but maybe I'm doing it wrong? Looks good when testing on Windows. See #712 Signed-off-by: Dirk Hohndel --- android.cpp | 8 +++++++- linux.c | 9 ++++++++- macos.c | 8 +++++++- pref.h | 3 ++- qt-ui/preferences.cpp | 26 +++++++++++++++++++------- windows.c | 11 ++++++++++- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/android.cpp b/android.cpp index 66bc6cf3e..1e99a5ced 100644 --- a/android.cpp +++ b/android.cpp @@ -13,13 +13,19 @@ extern "C" { const char android_system_divelist_default_font[] = "Roboto"; const char *system_divelist_default_font = android_system_divelist_default_font; -const int system_divelist_default_font_size = 8; +double system_divelist_default_font_size = 8.0; void subsurface_OS_pref_setup(void) { // nothing } +bool subsurface_ignore_font(const char *font) +{ + // there are no old default fonts that we would want to ignore + return false; +} + const char *system_default_filename(void) { /* Replace this when QtCore/QStandardPaths getExternalStorageDirectory landed */ diff --git a/linux.c b/linux.c index 2e37054a9..caf06b9f8 100644 --- a/linux.c +++ b/linux.c @@ -12,15 +12,22 @@ #include #include +// the DE should provide us with a default font and font size... const char linux_system_divelist_default_font[] = "Sans"; const char *system_divelist_default_font = linux_system_divelist_default_font; -const int system_divelist_default_font_size = 8; +double system_divelist_default_font_size = -1.0; void subsurface_OS_pref_setup(void) { // nothing } +bool subsurface_ignore_font(const char *font) +{ + // there are no old default fonts to ignore + return false; +} + void subsurface_user_info(struct user_info *user) { struct passwd *pwd = getpwuid(getuid()); diff --git a/macos.c b/macos.c index c51ef9f7b..91992d839 100644 --- a/macos.c +++ b/macos.c @@ -30,13 +30,19 @@ void subsurface_user_info(struct user_info *info) const char mac_system_divelist_default_font[] = "Arial"; const char *system_divelist_default_font = mac_system_divelist_default_font; -const int system_divelist_default_font_size = 10; +double system_divelist_default_font_size = -1.0; void subsurface_OS_pref_setup(void) { // nothing } +bool subsurface_ignore_font(const char *font) +{ + // there are no old default fonts to ignore + return false; +} + const char *system_default_filename(void) { const char *home, *user; diff --git a/pref.h b/pref.h index 9076eff99..7febf408c 100644 --- a/pref.h +++ b/pref.h @@ -80,8 +80,9 @@ extern struct preferences prefs, default_prefs; #define PP_GRAPHS_ENABLED (prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.pp_graphs.phe) extern const char *system_divelist_default_font; -extern const int system_divelist_default_font_size; +extern double system_divelist_default_font_size; extern const char *system_default_filename(); +extern bool subsurface_ignore_font(const char *font); extern void subsurface_OS_pref_setup(); #ifdef __cplusplus diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index edd95d838..ddccc8ae0 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -333,14 +333,26 @@ void PreferencesDialog::loadSettings() s.endGroup(); s.beginGroup("Display"); - QFont defaultFont = s.value("divelist_font", qApp->font()).value(); - defaultFont.setPointSizeF(s.value("font_size", qApp->font().pointSizeF()).toFloat()); + // get the font from the settings or our defaults + // respect the system default font size if none is explicitly set + QFont defaultFont = s.value("divelist_font", prefs.divelist_font).value(); + if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) { + prefs.font_size = qApp->font().pointSizeF(); + system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit + } + prefs.font_size = s.value("font_size", prefs.font_size).toFloat(); + // painful effort to ignore previous default fonts on Windows - ridiculous + QString fontName = defaultFont.toString(); + if (fontName.contains(",")) + fontName = fontName.left(fontName.indexOf(",")); + if (subsurface_ignore_font(fontName.toUtf8().constData())) { + defaultFont = QFont(prefs.divelist_font); + } else { + free((void *)prefs.divelist_font); + prefs.divelist_font = strdup(fontName.toUtf8().constData()); + } + defaultFont.setPointSizeF(prefs.font_size); qApp->setFont(defaultFont); - - GET_TXT("divelist_font", divelist_font); - GET_INT("font_size", font_size); - if (prefs.font_size < 0) - prefs.font_size = defaultFont.pointSizeF(); GET_INT("displayinvalid", display_invalid_dives); s.endGroup(); diff --git a/windows.c b/windows.c index a4fe1e2c2..386b52eb1 100644 --- a/windows.c +++ b/windows.c @@ -15,7 +15,7 @@ const char non_standard_system_divelist_default_font[] = "Calibri"; const char current_system_divelist_default_font[] = "Segoe UI"; const char *system_divelist_default_font = non_standard_system_divelist_default_font; -const int system_divelist_default_font_size = 9; +double system_divelist_default_font_size = -1; void subsurface_user(struct user_info *user) { /* Encourage use of at least libgit2-0.20 */ } @@ -28,6 +28,15 @@ void subsurface_OS_pref_setup(void) system_divelist_default_font = current_system_divelist_default_font; } +bool subsurface_ignore_font(const char *font) +{ + // if this is running on a recent enough version of Windows and the font + // passed in is the pre 4.3 default font, ignore it + if (isWin7Or8() && strcmp(font, non_standard_system_divelist_default_font) == 0) + return true; + return false; +} + const char *system_default_filename(void) { char datapath[MAX_PATH];