From 3cf9621fa02b17a36dacf336adcc9ed993de7699 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 12 May 2014 08:28:59 +0200 Subject: [PATCH] Respect fixed pitch request when font family is not available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In particular, if you have a
 tag in your HTML, this will
become a QFont with family "Courier New" and fixedPitch==true.
On Android, there's no "Courier New" font, and since the
style hint is AnyStyle, we will just return Roboto, which is
a proportional font.

Note that this exactly matches the condition when fetching the
fallback families for the font in the loadEngine() function,
which was introduced by 06568ff89c48dee8aab278b8b0538c331aa84595
in Qt 4.

[ChangeLog][Text] Respect QFont::fixedPitch() for fallbacks
when font family cannot be matched.

Task-number: QTBUG-36083
Change-Id: I64787c547dc492b9dd3c49f1edf0d9626d198260
Reviewed-by: Jørgen Lind 
Reviewed-by: Konstantin Ritt 
---
 src/gui/text/qfontdatabase.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 558258c30e..06438103ad 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -2501,10 +2501,14 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
 
     if (!engine) {
         if (!request.family.isEmpty()) {
+            QFont::StyleHint styleHint = QFont::StyleHint(request.styleHint);
+            if (styleHint == QFont::AnyStyle && request.fixedPitch)
+                styleHint = QFont::TypeWriter;
+
             QStringList fallbacks = request.fallBackFamilies
                                   + fallbackFamilies(request.family,
                                                      QFont::Style(request.style),
-                                                     QFont::StyleHint(request.styleHint),
+                                                     styleHint,
                                                      QChar::Script(script));
             if (script > QChar::Script_Common)
                 fallbacks += QString(); // Find the first font matching the specified script.