Only get font metrics if we're going to use them

Change-Id: If6b635e54f705c1e28b4e092a318d825a408ccfb
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Konstantin Ritt 2015-02-15 03:07:06 +04:00
parent 840a26a9b9
commit cd75f29794

View File

@ -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;