From cd75f297948e5c8c1bc7f2d016a43c883c6b212a Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Sun, 15 Feb 2015 03:07:06 +0400 Subject: Only get font metrics if we're going to use them Change-Id: If6b635e54f705c1e28b4e092a318d825a408ccfb Reviewed-by: Friedemann Kleint --- .../platforms/windows/qwindowsfontdatabase.cpp | 46 ++++++++++------------ 1 file changed, 20 insertions(+), 26 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 2565e3de09..603e88b3b2 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -1693,33 +1693,23 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, LOGFONT lf = fontDefToLOGFONT(request); const bool preferClearTypeAA = lf.lfQuality == CLEARTYPE_QUALITY; - HFONT hfont = 0; - hfont = CreateFontIndirect(&lf); - if (!hfont) { - qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); - hfont = QWindowsFontDatabase::systemFont(); - } - - int avWidth = 0; - BOOL res; - HGDIOBJ oldObj = SelectObject(data->hdc, hfont); - - TEXTMETRIC tm; - res = GetTextMetrics(data->hdc, &tm); - avWidth = tm.tmAveCharWidth; - SelectObject(data->hdc, oldObj); - if (!useDirectWrite) { if (request.stretch != 100) { - DeleteObject(hfont); - if (!res) - qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); - lf.lfWidth = avWidth * request.stretch/100; - hfont = CreateFontIndirect(&lf); + HFONT hfont = CreateFontIndirect(&lf); if (!hfont) { - qErrnoWarning("%s: CreateFontIndirect with stretch failed", __FUNCTION__); + qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); hfont = QWindowsFontDatabase::systemFont(); } + + HGDIOBJ oldObj = SelectObject(data->hdc, hfont); + TEXTMETRIC tm; + if (!GetTextMetrics(data->hdc, &tm)) + qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); + else + lf.lfWidth = tm.tmAveCharWidth * request.stretch / 100; + SelectObject(data->hdc, oldObj); + + DeleteObject(hfont); } } @@ -1737,18 +1727,22 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, } HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT(&lf, &directWriteFont); - if (FAILED(hr)) { + if (FAILED(hr)) qErrnoWarning("%s: CreateFontFromLOGFONT failed", __FUNCTION__); - } else { - DeleteObject(hfont); + else useDirectWrite = true; - } } } #endif QFontEngine *fe = 0; if (!useDirectWrite) { + HFONT hfont = CreateFontIndirect(&lf); + if (!hfont) { + qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); + hfont = QWindowsFontDatabase::systemFont(); + } + QWindowsFontEngine *few = new QWindowsFontEngine(request.family, hfont, lf, data); if (preferClearTypeAA) few->glyphFormat = QFontEngine::Format_A32; -- cgit v1.2.3