Remove DirectWrite warning when loading bitmap fonts

We use DirectWrite to determine whether a font is a color font
or not, so all fonts go through DirectWrite initially. However,
the load call will fail for bitmap fonts, causing us to output
lots of pointless warnings each time such a font was in use.

Instead, we only output this warning if we actually plan to
load the font through DirectWrite later. If the load fails,
we can assume it is not a color font and do not need to output
any warning for this.

[ChangeLog][Windows][Text] Removed confusing DirectWrite warning
when loading bitmap fonts.

Task-number: QTBUG-57180
Change-Id: Iaac8117745ef05a1dff23b346dbe0c6dbfb315f7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2018-09-26 10:19:37 +02:00
parent a3f575484a
commit c4a524f3a1

View File

@ -1930,13 +1930,13 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
} else {
HGDIOBJ oldFont = SelectObject(data->hdc, hfont);
const QFont::HintingPreference hintingPreference =
static_cast<QFont::HintingPreference>(request.hintingPreference);
bool useDw = useDirectWrite(hintingPreference, fam);
IDWriteFontFace *directWriteFontFace = NULL;
HRESULT hr = data->directWriteGdiInterop->CreateFontFaceFromHdc(data->hdc, &directWriteFontFace);
if (FAILED(hr)) {
const QString errorString = qt_error_string(int(hr));
qWarning().noquote().nospace() << "DirectWrite: CreateFontFaceFromHDC() failed ("
<< errorString << ") for " << request << ' ' << lf << " dpi=" << dpi;
} else {
if (SUCCEEDED(hr)) {
bool isColorFont = false;
#if defined(QT_USE_DIRECTWRITE2)
IDWriteFontFace2 *directWriteFontFace2 = nullptr;
@ -1946,9 +1946,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
isColorFont = directWriteFontFace2->GetPaletteEntryCount() > 0;
}
#endif
const QFont::HintingPreference hintingPreference =
static_cast<QFont::HintingPreference>(request.hintingPreference);
const bool useDw = useDirectWrite(hintingPreference, fam, isColorFont);
useDw = useDw || useDirectWrite(hintingPreference, fam, isColorFont);
qCDebug(lcQpaFonts) << __FUNCTION__ << request.family << request.pointSize
<< "pt" << "hintingPreference=" << hintingPreference << "color=" << isColorFont
<< dpi << "dpi" << "useDirectWrite=" << useDw;
@ -1970,6 +1968,10 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
} else {
directWriteFontFace->Release();
}
} else if (useDw) {
const QString errorString = qt_error_string(int(hr));
qWarning().noquote().nospace() << "DirectWrite: CreateFontFaceFromHDC() failed ("
<< errorString << ") for " << request << ' ' << lf << " dpi=" << dpi;
}
SelectObject(data->hdc, oldFont);