DirectWrite: Remove ad hoc font resolution through GDI
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ø <tor.arne.vestbo@qt.io> (cherry picked from commit 355f54f7d5dd300c73bf203f12e24305d0e227c1)
This commit is contained in:
parent
9988cd2469
commit
f5e2166bbd
@ -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<IDWriteFontFace> directWriteFontFace;
|
||||
if (SUCCEEDED(data()->directWriteGdiInterop->CreateFontFaceFromHdc(dummy, &directWriteFontFace))) {
|
||||
DirectWriteScope<IDWriteFontCollection> fontCollection;
|
||||
if (SUCCEEDED(data()->directWriteFactory->GetSystemFontCollection(&fontCollection))) {
|
||||
DirectWriteScope<IDWriteFont> font;
|
||||
if (SUCCEEDED(fontCollection->GetFontFromFontFace(*directWriteFontFace, &font))) {
|
||||
|
||||
DirectWriteScope<IDWriteFont2> font2;
|
||||
if (SUCCEEDED(font->QueryInterface(__uuidof(IDWriteFont2),
|
||||
reinterpret_cast<void **>(&font2)))) {
|
||||
DirectWriteScope<IDWriteLocalizedStrings> 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user