diff options
-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() |