diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2015-02-15 03:07:06 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-03-20 13:43:33 +0000 |
commit | cd75f297948e5c8c1bc7f2d016a43c883c6b212a (patch) | |
tree | bfa49af38a6115df5650d0d7b77770f94f67d495 /src/plugins | |
parent | 840a26a9b9e2fa9513fad759903c388e10900830 (diff) |
Only get font metrics if we're going to use them
Change-Id: If6b635e54f705c1e28b4e092a318d825a408ccfb
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsfontdatabase.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
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; |