From 8456adf0eeb9df8dd5f0547d4ad5a81888295f03 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 20 Aug 2014 15:06:30 +0600 Subject: Fix font enumeration, with the same family name, on Windows. Function EnumFontFamiliesEx with parameters (lfCharSet = DEFAULT_CHARSET, lfFaceName = '\0') enumerates only first installed font from many with same family name. This patch calls EnumFontFamiliesEx twice: 1. Without family name to enumerate families; 2. With family name to enumerate fonts with same family. Task-number: QTBUG-40828 Change-Id: Ic36a24a9e70f735a7324c05fe4b70f7c7e5710d0 Reviewed-by: Friedemann Kleint Reviewed-by: Allan Sandfeld Jensen --- .../platforms/windows/qwindowsfontdatabase.cpp | 36 ++++++++++++++++++++-- .../platforms/windows/qwindowsfontdatabase_ft.cpp | 36 ++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index aaa1970db1..60eacd6ec3 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -964,6 +964,31 @@ static int QT_WIN_CALLBACK storeFont(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetr return 1; } +static int QT_WIN_CALLBACK storeFontSub(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetric, + int type, LPARAM namesSetIn) +{ + Q_UNUSED(textmetric) + Q_UNUSED(type) + + HDC dummy = GetDC(0); + LOGFONT lf; + lf.lfCharSet = DEFAULT_CHARSET; + if (wcslen(f->elfLogFont.lfFaceName) >= LF_FACESIZE) { + qWarning("%s: Unable to enumerate family '%s'.", + __FUNCTION__, qPrintable(QString::fromWCharArray(f->elfLogFont.lfFaceName))); + return 1; + } + wmemcpy(lf.lfFaceName, f->elfLogFont.lfFaceName, + wcslen(f->elfLogFont.lfFaceName) + 1); + lf.lfPitchAndFamily = 0; + EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFont, + (LPARAM)namesSetIn, 0); + ReleaseDC(0, dummy); + + // keep on enumerating + return 1; +} + void QWindowsFontDatabase::populateFontDatabase() { m_families.clear(); @@ -999,8 +1024,15 @@ void QWindowsFontDatabase::populate(const QString &family) wmemcpy(lf.lfFaceName, reinterpret_cast(family.utf16()), family.size() + 1); lf.lfPitchAndFamily = 0; - EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFont, - (LPARAM)&m_families, 0); + + if (family.isEmpty()) { + EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFontSub, + (LPARAM)&m_families, 0); + } else { + EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFont, + (LPARAM)&m_families, 0); + } + ReleaseDC(0, dummy); } diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index 99c9e0faba..011fc9facb 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -375,6 +375,31 @@ static int QT_WIN_CALLBACK storeFont(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetr return 1; } +static int QT_WIN_CALLBACK storeFontSub(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetric, + int type, LPARAM namesSetIn) +{ + Q_UNUSED(textmetric) + Q_UNUSED(type) + + HDC dummy = GetDC(0); + LOGFONT lf; + lf.lfCharSet = DEFAULT_CHARSET; + if (wcslen(f->elfLogFont.lfFaceName) >= LF_FACESIZE) { + qWarning("%s: Unable to enumerate family '%s'.", + __FUNCTION__, qPrintable(QString::fromWCharArray(f->elfLogFont.lfFaceName))); + return 1; + } + wmemcpy(lf.lfFaceName, f->elfLogFont.lfFaceName, + wcslen(f->elfLogFont.lfFaceName) + 1); + lf.lfPitchAndFamily = 0; + EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFont, + (LPARAM)namesSetIn, 0); + ReleaseDC(0, dummy); + + // keep on enumerating + return 1; +} + void QWindowsFontDatabaseFT::populateFontDatabase() { m_families.clear(); @@ -409,8 +434,15 @@ void QWindowsFontDatabaseFT::populate(const QString &family) wmemcpy(lf.lfFaceName, reinterpret_cast(family.utf16()), family.size() + 1); lf.lfPitchAndFamily = 0; - EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFont, - (LPARAM)&m_families, 0); + + if (family.isEmpty()) { + EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFontSub, + (LPARAM)&m_families, 0); + } else { + EnumFontFamiliesEx(dummy, &lf, (FONTENUMPROC)storeFont, + (LPARAM)&m_families, 0); + } + ReleaseDC(0, dummy); } -- cgit v1.2.3