You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #7068: feat(qt): extract Dash-specific font infrastructure to qt/guiutil_font.{cpp,h}, encapsulate globals into Font{Info,Registry}, add arbitrary font support
b6d418a fix: always use `getFontNormal()` for Montserrat on macOS (Kittywhiskers Van Gogh)
4cc4040 fix: restore font on cancel, apply font when adjusting weight (Kittywhiskers Van Gogh)
7c2f616 fix: don't rely on `QSettings` weights if `-font-family` set (Kittywhiskers Van Gogh)
d2b8c0a fix: don't display stale weight settings if `-font-family` set (Kittywhiskers Van Gogh)
3faa368 feat(qt): add arbitrary font loading support (Kittywhiskers Van Gogh)
d3d72a2 refactor: miscellaneous refactoring (Kittywhiskers Van Gogh)
cdd7b37 refactor: consolidate font attributes to struct (Kittywhiskers Van Gogh)
2f30002 fix: disable appearance widget field if overridden by command line (Kittywhiskers Van Gogh)
6c71be8 fix: respect overridden arguments, avoid font pop in appearance widget (Kittywhiskers Van Gogh)
cc0665e fix: display error if `-font-family` set to nonexistent font (Kittywhiskers Van Gogh)
1f24526 fix: reintroduce fallbacks and assertion checks to avoid regressions (Kittywhiskers Van Gogh)
e0eb254 refactor: drop `FontFamily`, identify font with string name instead (Kittywhiskers Van Gogh)
b6a5bdb refactor: reduce `updateFonts()` invocations (Kittywhiskers Van Gogh)
96f5f93 refactor: use `g_font_registry` even more more extensively (Kittywhiskers Van Gogh)
fb9fc20 refactor: use `g_font_registry` even more extensively (Kittywhiskers Van Gogh)
e5ee874 refactor: use `g_font_registry` more extensively (Kittywhiskers Van Gogh)
d25c853 refactor: encapsulate global font state (consolidate tunables) (Kittywhiskers Van Gogh)
8a93d51 refactor: encapsulate global font state (consolidate maps) (Kittywhiskers Van Gogh)
7687e01 refactor: reduce entanglement with `FontFamily` (Kittywhiskers Van Gogh)
d21ceb1 refactor: use `strprintf` for `qDebug()` messages (Kittywhiskers Van Gogh)
1f239fc refactor: consolidate weight argument maps (Kittywhiskers Van Gogh)
c17a7eb refactor: consolidate Montserrat weight and name maps (Kittywhiskers Van Gogh)
6f3b11d fix: use argument passed to lambda instead of global (Kittywhiskers Van Gogh)
9cd9d44 fix: fallback to default weight if setting incompatible with font (Kittywhiskers Van Gogh)
5d5bbff lint: add to `non-backported.txt`, apply some `clang-format` suggestions (Kittywhiskers Van Gogh)
84ae194 refactor: move Dash-specific font management to `qt/guiutil_font.{cpp,h}` (Kittywhiskers Van Gogh)
Pull request description:
## Additional Information
* Dependency for dashpay/dash#6831
* Additional fixes have been included to deal with crash cases encountered when working on [dash#6831](dashpay/dash#6831), the first fix uses fallback weights if `fontWeight{Bold,Normal}` is set to a value not supported by the font. This is possible if the values are manually edited or overridden.
<details>
<summary>Crash:</summary>
```
dash@8cf837862c23:/src/dash$ ./src/qt/dash-qt --testnet
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-dash'
Assertion failure:
assertion: nIndex != -1
file: qt/optionsmodel.cpp, line: 546
function: virtual QVariant OptionsModel::data(const QModelIndex &, int) const
0#: (0x55D83D7D9C71) stacktraces.cpp:656 - __wrap___assert_fail
1#: (0x55D83CF4D6D4) optionsmodel.cpp:553 - OptionsModel::data(QModelIndex const&, int) const
2#: (0x55D83E4C4608) <unknown-file> - ???
3#: (0x55D83E4C9068) <unknown-file> - ???
4#: (0x55D83E4CA06B) <unknown-file> - ???
5#: (0x55D83CF0CF7E) guiutil.cpp - GUIUtil::setupAppearance(QWidget*, OptionsModel*)
6#: (0x55D83CEDB8D9) bitcoin.cpp:436 - BitcoinApplication::initializeResult(bool, interfaces::BlockAndHeaderTipInfo)
7#: (0x55D83CEE8DDD) qobjectdefs_impl.h:425 - QtPrivate::QSlotObject<void (BitcoinApplication::*)(bool, interfaces::BlockAndHeaderTipInfo), QtPrivate::List<bool, interfaces::BlockAndHeaderTipInfo>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*)
8#: (0x55D83E0C288D) <unknown-file> - ???
9#: (0x55D83DC5DAB9) <unknown-file> - ???
10#: (0x55D83E2F4186) <unknown-file> - ???
11#: (0x55D83E2F5BAC) <unknown-file> - ???
12#: (0x55D83E2F6E7E) <unknown-file> - ???
13#: (0x55D83E0A5668) <unknown-file> - ???
dash-qt: qt/optionsmodel.cpp:546: virtual QVariant OptionsModel::data(const QModelIndex &, int) const: Assertion `nIndex != -1' failed.
Aborted (core dumped)
```
</details>
The second fix uses the argument passed to the lambda `addBestDefaults` instead of a global font, this has also been flagged by CodeRabbit ([comment](dashpay/dash#6831 (comment)))
<details>
<summary>Crash:</summary>
```
dash@8cf837862c23:/src/dash$ ./src/qt/dash-qt --testnet
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-dash'
Assertion failure:
assertion: mapWeight.count(weight)
file: qt/guiutil_font.cpp, line: 119
function: int GUIUtil::weightToArg(const QFont::Weight)
0#: (0x55B3C209CC31) stacktraces.cpp:656 - __wrap___assert_fail
1#: (0x55B3C17E17D6) basic_ios.h:50 - std::ctype<char> const& std::__check_facet<std::ctype<char> >(std::ctype<char> const*)
2#: (0x55B3C17E17D6) basic_ios.h:454 - std::basic_ios<char, std::char_traits<char> >::widen(char) const
3#: (0x55B3C17E17D6) ostream:742 - std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>>&)
4#: (0x55B3C17E17D6) ostream:121 - std::ostream::operator<<(std::ostream& (*)(std::ostream&))
5#: (0x55B3C17E17D6) guiutil_font.cpp:118 - GUIUtil::weightToArg(QFont::Weight)
6#: (0x55B3C17A189A) bitcoin.cpp:702 - GuiMain(int, char**)
7#: (0x7F88E4B1E1CA) libc_start_call_main.h:74 - __libc_start_call_main
8#: (0x7F88E4B1E28B) libc-start.c:128 - call_init
9#: (0x7F88E4B1E28B) libc-start.c:347 - __libc_start_main_impl
10#: (0x55B3C179C545) <unknown-file> - ???
dash-qt: qt/guiutil_font.cpp:119: int GUIUtil::weightToArg(const QFont::Weight): Assertion `mapWeight.count(weight)' failed.
Aborted (core dumped)
```
</details>
* A helper, `qstrprintf()` has been introduced to streamline debug print logging based on a review suggestion ([comment](dashpay/dash#6831 (comment))).
## Breaking Changes
None expected.
## How Has This Been Tested?
On build 2dc48deb running Dash Qt on `./src/qt/dash-qt --testnet --font-family="Comic Sans MS"`

On build 2dc48deb running Dash Qt on `./src/qt/dash-qt --testnet --font-family="Fictional Sans Serif"`

## Checklist:
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)**
- [x] I have made corresponding changes to the documentation **(note: N/A)**
- [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
ACKs for top commit:
UdjinM6:
Light ACK b6d418a
Tree-SHA512: defdbd3864405c22b4d3cd381a58331b1ad62785f9b037cbdc3e6fd67045039ec116cabb18ddef5296c0e9647c50efe7b22e685c994cf31606328d917a349747
argsman.AddArg("-choosedatadir", strprintf(QObject::tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
490
491
argsman.AddArg("-custom-css-dir", "Set a directory which contains custom css files. Those will be used as stylesheets for the UI.", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
491
-
argsman.AddArg("-font-family", QObject::tr("Set the font family. Possible values: %1. (default: %2)").arg("SystemDefault, Montserrat").arg(GUIUtil::fontFamilyToString(GUIUtil::getFontFamilyDefault())).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
492
-
argsman.AddArg("-font-scale", QObject::tr("Set a scale factor which gets applied to the base font size. Possible range %1 (smallest fonts) to %2 (largest fonts). (default: %3)").arg(-100).arg(100).arg(GUIUtil::getFontScaleDefault()).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
493
-
argsman.AddArg("-font-weight-bold", QObject::tr("Set the font weight for bold texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::weightToArg(GUIUtil::getFontWeightBoldDefault())).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
494
-
argsman.AddArg("-font-weight-normal", QObject::tr("Set the font weight for normal texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::weightToArg(GUIUtil::getFontWeightNormalDefault())).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
492
+
argsman.AddArg("-font-family", QObject::tr("Set the font family. Possible values: %1. (default: %2)").arg(Join(GUIUtil::g_fonts_known, ", ")).arg(GUIUtil::FontRegistry::DEFAULT_FONT).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
493
+
argsman.AddArg("-font-scale", QObject::tr("Set a scale factor which gets applied to the base font size. Possible range %1 (smallest fonts) to %2 (largest fonts). (default: %3)").arg(-100).arg(100).arg(GUIUtil::FontRegistry::DEFAULT_FONT_SCALE).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
494
+
argsman.AddArg("-font-weight-bold", QObject::tr("Set the font weight for bold texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::weightToArg(GUIUtil::FontRegistry::TARGET_WEIGHT_BOLD)).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
495
+
argsman.AddArg("-font-weight-normal", QObject::tr("Set the font weight for normal texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::weightToArg(GUIUtil::FontRegistry::TARGET_WEIGHT_NORMAL)).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
495
496
argsman.AddArg("-lang=<lang>", QObject::tr("Set language, for example \"de_DE\" (default: system locale)").toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
0 commit comments