Guarantee there is always a valid HFONT to get metrics for

Change-Id: I69d72803f994a5455b607c4f94f87c1c782eb0a4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Konstantin Ritt 2015-02-15 02:44:54 +04:00
parent 1214e59e73
commit 4429f7510c

View File

@ -1674,8 +1674,10 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request,
HFONT hfont = 0; HFONT hfont = 0;
hfont = CreateFontIndirect(&lf); hfont = CreateFontIndirect(&lf);
if (!hfont) if (!hfont) {
qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__);
hfont = QWindowsFontDatabase::systemFont();
}
bool ttf = false; bool ttf = false;
int avWidth = 0; int avWidth = 0;
@ -1689,19 +1691,18 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request,
SelectObject(data->hdc, oldObj); SelectObject(data->hdc, oldObj);
if (!useDirectWrite) { if (!useDirectWrite) {
if (hfont && (!ttf || request.stretch != 100)) { if (!ttf || request.stretch != 100) {
DeleteObject(hfont); DeleteObject(hfont);
if (!res) if (!res)
qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__);
lf.lfWidth = avWidth * request.stretch/100; lf.lfWidth = avWidth * request.stretch/100;
hfont = CreateFontIndirect(&lf); hfont = CreateFontIndirect(&lf);
if (!hfont) if (!hfont) {
qErrnoWarning("%s: CreateFontIndirect with stretch failed", __FUNCTION__); qErrnoWarning("%s: CreateFontIndirect with stretch failed", __FUNCTION__);
}
if (!hfont)
hfont = QWindowsFontDatabase::systemFont(); hfont = QWindowsFontDatabase::systemFont();
} }
}
}
#if !defined(QT_NO_DIRECTWRITE) #if !defined(QT_NO_DIRECTWRITE)
else { else {