summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2019-04-02 15:33:16 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2019-05-23 09:49:10 +0200
commit922d195020d54d7e599d135f6a5e0338100e08f1 (patch)
tree5ca0bfce1b904ce40d06dc38c2e3c3b7e3301b3f /src/gui/text
parentcceeb1ee7e18aac2a21ec72ef669bd6d4490ce2e (diff)
Fix font matching of typographic families on Windows
9204b8c31ea1b5f0c05870c5b5d74c33b1a4f622 broke font matching on Windows. This was then attempted fixed by bcd2fa484a4fe93e77743195d7f72cce9e580d43, but this caused an infinite recursion for some cases, so it was reverted again by 9d1905da9c59e9062a157199c81c076efc20eb28. The original issue was that if we populate a specific face of a family, such as "Arial Black", then the typographic/preferred name will be detected as "Arial" and this family will be set as populated=true, even though we have not yet registered any additional subfamilies. In this case, we need to call populateFamily() for the typographic family name to ensure we get Windows to enumerate all the subfamilies in that family before it sets it as populated=true. But this broke for some fonts where the font naming was unconventional. In particular, "Yu Gothic" would have its Japanese name as the typographic name, and there would be no font in the system where the old-style font family name matched the typographic name. In that case we would go into a loop where we would try populating "<Japanese font name>", Windows would translate this to "Yu Gothic", we would translate it back to "<Japanese font name>", ad infinitum. In order to avoid the infinite recursion, we add a recursion guard as well, ensuring that we never call populateFamily() for the main family we are currently populating. [ChangeLog][Windows][Fonts] Fixed a bug where it would be impossible to request different faces of a font family after a specific type face has been in use. Task-number: QTBUG-74748 Task-number: QTBUG-74983 Change-Id: Ibe6239f67c45d67ebf75947c8f231cfa177e347f Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontdatabase.cpp7
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp11
-rw-r--r--src/gui/text/qplatformfontdatabase.h2
3 files changed, 20 insertions, 0 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 82b9bb810a..3cbda0facd 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -792,6 +792,13 @@ QString qt_resolveFontFamilyAlias(const QString &alias)
return alias;
}
+bool qt_isFontFamilyPopulated(const QString &familyName)
+{
+ QFontDatabasePrivate *d = privateDb();
+ QtFontFamily *f = d->family(familyName, QFontDatabasePrivate::RequestFamily);
+ return f != nullptr && f->populated;
+}
+
/*!
Returns a list of alternative fonts for the specified \a family and
\a style and \a script using the \a styleHint given.
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index a911014a19..715b00d838 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -60,6 +60,7 @@ void qt_registerFont(const QString &familyname, const QString &stylename,
void qt_registerFontFamily(const QString &familyName);
void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias);
+bool qt_isFontFamilyPopulated(const QString &familyName);
/*!
Registers the pre-rendered QPF2 font contained in the given \a dataArray.
@@ -666,6 +667,16 @@ void QPlatformFontDatabase::registerAliasToFontFamily(const QString &familyName,
}
/*!
+ Helper function that returns true if the font family has already been registered and populated.
+
+ \since 5.14
+*/
+bool QPlatformFontDatabase::isFamilyPopulated(const QString &familyName)
+{
+ return qt_isFontFamilyPopulated(familyName);
+}
+
+/*!
\class QPlatformFontDatabase
\since 5.0
\internal
diff --git a/src/gui/text/qplatformfontdatabase.h b/src/gui/text/qplatformfontdatabase.h
index f4558129a7..38ba7f10b2 100644
--- a/src/gui/text/qplatformfontdatabase.h
+++ b/src/gui/text/qplatformfontdatabase.h
@@ -139,6 +139,8 @@ public:
static void registerFontFamily(const QString &familyName);
static void registerAliasToFontFamily(const QString &familyName, const QString &alias);
+
+ static bool isFamilyPopulated(const QString &familyName);
};
QT_END_NAMESPACE