From 3aa1aec958e0926b9f4883316bae016b76a74eea Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 16 Jun 2022 04:08:08 +0300 Subject: [PATCH 43/43] Qt: Select smooth font size for the default fonts When selecting default fonts, set their size to ont of the smooth sizes of that font. See osdn #44034 Signed-off-by: Marko Lindqvist --- client/gui-qt/fonts.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/client/gui-qt/fonts.cpp b/client/gui-qt/fonts.cpp index ae04a4fa5d..2f1f9519e7 100644 --- a/client/gui-qt/fonts.cpp +++ b/client/gui-qt/fonts.cpp @@ -221,11 +221,38 @@ QString configure_font(QString font_name, QStringList sl, int size, QFontDatabase database; QString str; QFont *f; + QString style; + + if (bold) { + style = "Bold"; + } foreach (str, sl) { - if (database.families().contains(str)) { + QList sizes = database.smoothSizes(str, style); + + if (!sizes.isEmpty()) { + QListIterator i(sizes); + int lower = -1; + int upper = -1; QByteArray fn_bytes; + while (i.hasNext()) { + int cur = i.next(); + + if (cur <= size && lower < cur) { + lower = cur; + } + if (cur >= size && (upper < 0 || upper > cur)) { + upper = cur; + } + } + + if (size - lower > upper - size) { + size = upper; + } else { + size = lower; + } + f = new QFont(str, size); if (bold) { f->setBold(true); -- 2.35.1