Package: kwidgetsaddons / 5.28.0-3

KFontRequester-Find-the-nearest-match-for-a-missing-font.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From: Alexander Volkov <a.volkov@rusbitech.ru>
Date: Thu, 12 Jan 2017 19:37:04 +0300
Subject: KFontRequester: Find the nearest match for a missing font

If the font is missing, then try to find the nearest font
family instead of just selecting the first family in the
list.

BUG: 286260
REVIEW: 129809
---
 src/kfontrequester.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/kfontrequester.cpp b/src/kfontrequester.cpp
index 6cca672..63fbbd0 100644
--- a/src/kfontrequester.cpp
+++ b/src/kfontrequester.cpp
@@ -24,6 +24,7 @@
 #include <QPushButton>
 #include <QLayout>
 #include <QFontDatabase>
+#include <QFontInfo>
 #include <QFontDialog>
 #include <QLocale>
 
@@ -46,8 +47,10 @@ static QFont nearestExistingFont(const QFont &font)
     const QStringList families = dbase.families();
     if (!families.contains(family)) {
         // Chose another family.
-        family = families.count() ? families[0] : QStringLiteral("fixed");
-        // TODO: Try to find nearest match?
+        family = QFontInfo(font).family(); // the nearest match
+        if (!families.contains(family)) {
+            family = families.count() ? families.at(0) : QStringLiteral("fixed");
+        }
     }
 
     // Check if the family has the requested style.