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>
This commit is contained in:
Vladimir Belyavsky 2022-05-03 19:03:53 +03:00
parent a085a14d76
commit a3a07dd16d

View File

@ -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;
}
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()