From 469b13916983aff4625657eecbb7d2399cac901d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 3 Jun 2016 14:32:30 +0200 Subject: [PATCH] Register fonts with their given style name Instead of guessing which styles we have available (always bold/italic) register the ones we actually find. Change-Id: I57380d0417411456a3037f8769440e7b43517e0e Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../platforms/windows/qwindowsfontdatabase.cpp | 16 +++++++++------- .../windows/qwindowsfontdatabase_ft.cpp | 12 +++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index 5e75cbf37e..6f236aa588 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -944,7 +944,7 @@ error: return i18n_name; } -static bool addFontToDatabase(const QString &familyName, uchar charSet, +static bool addFontToDatabase(const QString &familyName, const QString &styleName, uchar charSet, const TEXTMETRIC *textmetric, const FONTSIGNATURE *signature, int type, @@ -1012,16 +1012,16 @@ static bool addFontToDatabase(const QString &familyName, uchar charSet, writingSystems.setSupported(ws); } - QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight, + QPlatformFontDatabase::registerFont(familyName, styleName, foundryName, weight, style, stretch, antialias, scalable, size, fixed, writingSystems, 0); // add fonts windows can generate for us: - if (weight <= QFont::DemiBold) + if (weight <= QFont::DemiBold && styleName.isEmpty()) QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, style, stretch, antialias, scalable, size, fixed, writingSystems, 0); - if (style != QFont::StyleItalic) + if (style != QFont::StyleItalic && styleName.isEmpty()) QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); - if (weight <= QFont::DemiBold && style != QFont::StyleItalic) + if (weight <= QFont::DemiBold && style != QFont::StyleItalic && styleName.isEmpty()) QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); @@ -1036,6 +1036,7 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t { const ENUMLOGFONTEX *f = reinterpret_cast(logFont); const QString familyName = QString::fromWCharArray(f->elfLogFont.lfFaceName); + const QString styleName = QString::fromWCharArray(f->elfStyle); const uchar charSet = f->elfLogFont.lfCharSet; const bool registerAlias = bool(lParam); @@ -1045,7 +1046,7 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t const FONTSIGNATURE *signature = Q_NULLPTR; if (type & TRUETYPE_FONTTYPE) signature = &reinterpret_cast(textmetric)->ntmFontSig; - addFontToDatabase(familyName, charSet, textmetric, signature, type, registerAlias); + addFontToDatabase(familyName, styleName, charSet, textmetric, signature, type, registerAlias); // keep on enumerating return 1; @@ -1456,6 +1457,7 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData, // Memory fonts won't show up in enumeration, so do add them the hard way. for (int j = 0; j < families.count(); ++j) { const QString familyName = families.at(j).name; + const QString styleName = families.at(j).style; familyNames << familyName; HDC hdc = GetDC(0); LOGFONT lf; @@ -1468,7 +1470,7 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData, TEXTMETRIC textMetrics; GetTextMetrics(hdc, &textMetrics); - addFontToDatabase(familyName, lf.lfCharSet, &textMetrics, &signatures.at(j), + addFontToDatabase(familyName, styleName, lf.lfCharSet, &textMetrics, &signatures.at(j), TRUETYPE_FONTTYPE, true); SelectObject(hdc, oldobj); diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index d782519c68..b513d9ad7c 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -160,6 +160,7 @@ static const FontKey *findFontKey(const QString &name, int *indexIn = Q_NULLPTR) } static bool addFontToDatabase(const QString &faceName, + const QString &styleName, const QString &fullName, uchar charSet, const TEXTMETRIC *textmetric, @@ -247,19 +248,19 @@ static bool addFontToDatabase(const QString &faceName, if (!QDir::isAbsolutePath(value)) value.prepend(QFile::decodeName(qgetenv("windir") + "\\Fonts\\")); - QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, style, stretch, + QPlatformFontDatabase::registerFont(faceName, styleName, foundryName, weight, style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); // add fonts windows can generate for us: - if (weight <= QFont::DemiBold) + if (weight <= QFont::DemiBold && styleName.isEmpty()) QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - if (style != QFont::StyleItalic) + if (style != QFont::StyleItalic && styleName.isEmpty()) QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - if (weight <= QFont::DemiBold && style != QFont::StyleItalic) + if (weight <= QFont::DemiBold && style != QFont::StyleItalic && styleName.isEmpty()) QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); @@ -274,6 +275,7 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t { const ENUMLOGFONTEX *f = reinterpret_cast(logFont); const QString faceName = QString::fromWCharArray(f->elfLogFont.lfFaceName); + const QString styleName = QString::fromWCharArray(f->elfStyle); const QString fullName = QString::fromWCharArray(f->elfFullName); const uchar charSet = f->elfLogFont.lfCharSet; @@ -283,7 +285,7 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t const FONTSIGNATURE *signature = Q_NULLPTR; if (type & TRUETYPE_FONTTYPE) signature = &reinterpret_cast(textmetric)->ntmFontSig; - addFontToDatabase(faceName, fullName, charSet, textmetric, signature, type, false); + addFontToDatabase(faceName, styleName, fullName, charSet, textmetric, signature, type, false); // keep on enumerating return 1;