Mercurial > octave
changeset 29522:82aaf001abee
make detection of default fixed font for gui more robust
* resource-manager.cc (get_default_font_family): check the system fixed font
from the QFontDatabase if it is contained in a QFontComboBox of monospaced
fonts, if not, take the first font from the QFontComboBox
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 11 Apr 2021 19:22:29 +0200 |
parents | d7223245d26f |
children | 71e979cf1319 |
files | libgui/src/resource-manager.cc |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/resource-manager.cc Sat Apr 10 20:58:08 2021 +0200 +++ b/libgui/src/resource-manager.cc Sun Apr 11 19:22:29 2021 +0200 @@ -209,10 +209,6 @@ { QString default_family; -#if defined (Q_OS_MAC) - // Use hard coded default on macOS, since selection of fixed width - // default font is unreliable (see bug #59128). - // Get all available fixed width fonts via a font combobox QFontComboBox font_combo_box; font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts); @@ -221,6 +217,9 @@ for (int index = 0; index < font_combo_box.count(); index++) fonts << font_combo_box.itemText(index); +#if defined (Q_OS_MAC) + // Use hard coded default on macOS, since selection of fixed width + // default font is unreliable (see bug #59128). // Test for macOS default fixed width font if (fonts.contains (global_mono_font.def.toString ())) default_family = global_mono_font.def.toString (); @@ -233,6 +232,14 @@ // Get the system's default monospaced font QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); default_family = fixed_font.defaultFamily (); + + // Since this might be unreliable, test all available fixed width fonts + if (! fonts.contains (default_family)) + { + // Font returned by QFontDatabase is not in fixed fonts list. + // Fallback: take first from this list + default_family = fonts[0]; + } } // Test env variable which has preference