diff options
author | Vladimir Belyavsky <belyavskyv@gmail.com> | 2022-05-03 19:03:53 +0300 |
---|---|---|
committer | Vladimir Belyavsky <belyavskyv@gmail.com> | 2022-05-05 05:42:39 +0000 |
commit | a3a07dd16d0d04c94bf46215fd0774d7e7db37fa (patch) | |
tree | 89fa482a7405536bb47e14a969284f28c6de970b /src/gui | |
parent | a085a14d76553ebd1fa4a4a11a27110ee544a531 (diff) |
QWindowsFontDatabase: fix handling of default EUDC font
There was a problem if default EUDC font is specified in user's
Windows Registry as a font file name instead of full path. In that
case we didn't handle this font properly and the warning was
generated.
Fixes: QTBUG-103003
Pick-to: 6.2 6.3
Change-Id: I946082af8dc31e6cf82cebca94ebbb03726239e0
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/windows/qwindowsfontdatabase.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp index 039f6f5540..8ac7a116b9 100644 --- a/src/gui/text/windows/qwindowsfontdatabase.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase.cpp @@ -51,6 +51,7 @@ #include <QtCore/QDebug> #include <QtCore/QFile> #include <QtCore/QtEndian> +#include <QtCore/QStandardPaths> #include <QtCore/private/qduplicatetracker_p.h> #include <QtCore/private/qwinregistry_p.h> @@ -708,19 +709,44 @@ static int QT_WIN_CALLBACK populateFontFamilies(const LOGFONT *logFont, const TE return 1; // continue } +namespace { + +QString resolveFontPath(const QString &fontPath) +{ + if (fontPath.isEmpty()) + return QString(); + + if (QFile::exists(fontPath)) + return fontPath; + + // resolve the path relatively to Windows Fonts directory + return QStandardPaths::locate(QStandardPaths::FontsLocation, fontPath); +} + +} + void QWindowsFontDatabase::addDefaultEUDCFont() { const QString path = QWinRegistryKey(HKEY_CURRENT_USER, LR"(EUDC\1252)") .stringValue(L"SystemDefaultEUDCFont"); - if (!path.isEmpty()) { - QFile file(path); - if (!file.open(QIODevice::ReadOnly)) { - qCWarning(lcQpaFonts) << "Unable to open default EUDC font:" << path; - return; - } + if (path.isEmpty()) { + qCDebug(lcQpaFonts) << "There's no default EUDC font specified"; + return; + } - m_eudcFonts = addApplicationFont(file.readAll(), path); + const QString absolutePath = resolveFontPath(path); + if (absolutePath.isEmpty()) { + qCDebug(lcQpaFonts) << "Unable to locate default EUDC font:" << path; + return; } + + QFile file(absolutePath); + if (!file.open(QIODevice::ReadOnly)) { + qCWarning(lcQpaFonts) << "Unable to open default EUDC font:" << absolutePath; + return; + } + + m_eudcFonts = addApplicationFont(file.readAll(), absolutePath); } void QWindowsFontDatabase::populateFontDatabase() |