From 4429f7510c61b35ee38d6abe3bc925e8d388d842 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Sun, 15 Feb 2015 02:44:54 +0400 Subject: Guarantee there is always a valid HFONT to get metrics for Change-Id: I69d72803f994a5455b607c4f94f87c1c782eb0a4 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowsfontdatabase.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsfontdatabase.cpp') diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index ef74ef35f5..56adae8ffb 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -1674,8 +1674,10 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, HFONT hfont = 0; hfont = CreateFontIndirect(&lf); - if (!hfont) + if (!hfont) { qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); + hfont = QWindowsFontDatabase::systemFont(); + } bool ttf = false; int avWidth = 0; @@ -1689,18 +1691,17 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, SelectObject(data->hdc, oldObj); if (!useDirectWrite) { - if (hfont && (!ttf || request.stretch != 100)) { + if (!ttf || request.stretch != 100) { DeleteObject(hfont); if (!res) qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); lf.lfWidth = avWidth * request.stretch/100; hfont = CreateFontIndirect(&lf); - if (!hfont) + if (!hfont) { qErrnoWarning("%s: CreateFontIndirect with stretch failed", __FUNCTION__); + hfont = QWindowsFontDatabase::systemFont(); + } } - - if (!hfont) - hfont = QWindowsFontDatabase::systemFont(); } #if !defined(QT_NO_DIRECTWRITE) -- cgit v1.2.3