From ff2ae36551b75b2c8a2d1f73e4d1e956b4eadb62 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 13 Dec 2017 08:03:38 +0100 Subject: Windows: Support application fonts as fallbacks In order to support the generated EUDC.TTE font for End-User Defined Characters on Windows, we need to allow fallback fonts which are not part of the default font collection. This is the same as change 21c7421d4e86b6048f9c2c7a9a81ec4ff1ed278c, but adapted to the fallback font code path. Without this change, the EUDC file would still be loaded, but it would be loaded through the GDI fallback, and we would display an error message on the console. Task-number: QTBUG-44594 Change-Id: Id2404228c7fd345523e4e5c99f31862e256930e3 Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt Reviewed-by: Friedemann Kleint --- .../fontdatabases/windows/qwindowsfontengine.cpp | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/platformsupport/fontdatabases') diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp index a337332b53..584e4db05d 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp @@ -1267,31 +1267,36 @@ QFontEngine *QWindowsMultiFontEngine::loadEngine(int at) lf.lfFaceName[nameSubstituteLength] = 0; } - IDWriteFont *directWriteFont = 0; - HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT(&lf, &directWriteFont); - if (FAILED(hr)) { - qWarning("%s: %s", __FUNCTION__, - qPrintable(msgDirectWriteFunctionFailed(hr, "CreateFontFromLOGFONT", fam, nameSubstitute))); + HFONT hfont = CreateFontIndirect(&lf); + if (hfont == nullptr) { + qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); } else { - Q_ASSERT(directWriteFont); - IDWriteFontFace *directWriteFontFace = NULL; - HRESULT hr = directWriteFont->CreateFontFace(&directWriteFontFace); + HGDIOBJ oldFont = SelectObject(data->hdc, hfont); + + IDWriteFontFace *directWriteFontFace = nullptr; + QWindowsFontEngineDirectWrite *fedw = nullptr; + HRESULT hr = data->directWriteGdiInterop->CreateFontFaceFromHdc(data->hdc, &directWriteFontFace); if (SUCCEEDED(hr)) { Q_ASSERT(directWriteFontFace); - QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace, - fontEngine->fontDef.pixelSize, - data); + fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace, + fontEngine->fontDef.pixelSize, + data); fedw->fontDef.weight = fontEngine->fontDef.weight; if (fontEngine->fontDef.style > QFont::StyleNormal) fedw->fontDef.style = fontEngine->fontDef.style; fedw->fontDef.family = fam; fedw->fontDef.hintingPreference = fontEngine->fontDef.hintingPreference; fedw->fontDef.stretch = fontEngine->fontDef.stretch; - return fedw; } else { qWarning("%s: %s", __FUNCTION__, qPrintable(msgDirectWriteFunctionFailed(hr, "CreateFontFace", fam, nameSubstitute))); } + + SelectObject(data->hdc, oldFont); + DeleteObject(hfont); + + if (fedw != nullptr) + return fedw; } } #endif -- cgit v1.2.3