From f5e2166bbd77b9be2fc3a9dfa0660427525d6276 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 6 Dec 2024 14:38:29 +0100 Subject: [PATCH] DirectWrite: Remove ad hoc font resolution through GDI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In b8612eaa2a17e12e31ee28141cff1fb43e54c00e, we added a fail safe where failure to find the font name through DirectWrite would try loading it through GDI instead and if that was successful we would register the family with the database after all. However, the code assumed that CreateFontIndirect() would return NULL if the font did not exist. It does not do this, but instead selecting the HFONT on the HDC will give us a suitable alternative instead. The result would be that any missing font family would be registered with the font database through this mechanism, even if it really didn't exist. This code was added in an early version of the patch, however, and it should not actually be needed anymore, since we in later versions of the same patch also added logic to populate the GDI-compatible family names (DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES etc.). This should take care of backwards compatibility with the GDI names for fonts. Since the code has been reported to cause problems on some systems, it's safest to just remove this hack. Pick-to: 6.8 Task-number: QTBUG-130313 Change-Id: I7eca893d17796d9cac07391b7b947d28dd7cd920 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 355f54f7d5dd300c73bf203f12e24305d0e227c1) --- .../qwindowsdirectwritefontdatabase.cpp | 72 ------------------- 1 file changed, 72 deletions(-) diff --git a/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp b/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp index f2671b6ccf8..66990a563f6 100644 --- a/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp +++ b/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp @@ -268,78 +268,6 @@ QSupportedWritingSystems QWindowsDirectWriteFontDatabase::supportedWritingSystem bool QWindowsDirectWriteFontDatabase::populateFamilyAliases(const QString &missingFamily) { - // If the font has not been populated, it is possible this is a legacy font family supported - // by GDI. We make an attempt at loading it via GDI and then add this face directly to the - // database. - if (!missingFamily.isEmpty() - && missingFamily.size() < LF_FACESIZE - && !m_populatedFonts.contains(missingFamily) - && !m_populatedBitmapFonts.contains(missingFamily)) { - qCDebug(lcQpaFonts) << "Loading unpopulated" << missingFamily << ". Trying GDI."; - - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - memcpy(lf.lfFaceName, missingFamily.utf16(), missingFamily.size() * sizeof(wchar_t)); - - HFONT hfont = CreateFontIndirect(&lf); - if (hfont) { - HDC dummy = GetDC(0); - HGDIOBJ oldFont = SelectObject(dummy, hfont); - - DirectWriteScope directWriteFontFace; - if (SUCCEEDED(data()->directWriteGdiInterop->CreateFontFaceFromHdc(dummy, &directWriteFontFace))) { - DirectWriteScope fontCollection; - if (SUCCEEDED(data()->directWriteFactory->GetSystemFontCollection(&fontCollection))) { - DirectWriteScope font; - if (SUCCEEDED(fontCollection->GetFontFromFontFace(*directWriteFontFace, &font))) { - - DirectWriteScope font2; - if (SUCCEEDED(font->QueryInterface(__uuidof(IDWriteFont2), - reinterpret_cast(&font2)))) { - DirectWriteScope names; - if (SUCCEEDED(font2->GetFaceNames(&names))) { - wchar_t englishLocale[] = L"en-us"; - QString englishLocaleStyleName = localeString(*names, englishLocale); - - QFont::Stretch stretch = fromDirectWriteStretch(font2->GetStretch()); - QFont::Style style = fromDirectWriteStyle(font2->GetStyle()); - QFont::Weight weight = fromDirectWriteWeight(font2->GetWeight()); - bool fixed = font2->IsMonospacedFont(); - bool isColorFont = font2->IsColorFont(); - - - QSupportedWritingSystems writingSystems = supportedWritingSystems(*directWriteFontFace); - - qCDebug(lcQpaFonts) << "Registering legacy font family" << missingFamily; - QPlatformFontDatabase::registerFont(missingFamily, - englishLocaleStyleName, - QString(), - weight, - style, - stretch, - false, - true, - 0xffff, - fixed, - isColorFont, - writingSystems, - new FontHandle(*directWriteFontFace, missingFamily)); - - SelectObject(dummy, oldFont); - DeleteObject(hfont); - - return true; - } - } - } - } - } - - SelectObject(dummy, oldFont); - DeleteObject(hfont); - } - } - // Skip over implementation in QWindowsFontDatabase return QWindowsFontDatabaseBase::populateFamilyAliases(missingFamily); }