From a3a07dd16d0d04c94bf46215fd0774d7e7db37fa Mon Sep 17 00:00:00 2001 From: Vladimir Belyavsky Date: Tue, 3 May 2022 19:03:53 +0300 Subject: [PATCH] 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 --- src/gui/text/windows/qwindowsfontdatabase.cpp | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 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 #include #include +#include #include #include @@ -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; - } - - m_eudcFonts = addApplicationFont(file.readAll(), path); + if (path.isEmpty()) { + qCDebug(lcQpaFonts) << "There's no default EUDC font specified"; + return; } + + 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()