From 071b28675606633f41c58edcc27c0b514e9d6c33 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Sun, 15 Feb 2015 02:30:41 +0400 Subject: Fix indentation and move some variables around Change-Id: Ice1987242d288b0b18e77c647153e6d133135896 Reviewed-by: Konstantin Ritt --- .../platforms/windows/qwindowsfontdatabase.cpp | 115 ++++++++++----------- 1 file changed, 52 insertions(+), 63 deletions(-) (limited to 'src/plugins/platforms/windows') diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index 5ab32ebe03..ef74ef35f5 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -1661,13 +1661,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, int dpi, const QSharedPointer &data) { - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - - bool preferClearTypeAA = false; - - HFONT hfont = 0; - #if !defined(QT_NO_DIRECTWRITE) bool useDirectWrite = (request.hintingPreference == QFont::PreferNoHinting) || (request.hintingPreference == QFont::PreferVerticalHinting); @@ -1676,70 +1669,66 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, bool useDirectWrite = false; #endif - { - lf = fontDefToLOGFONT(request); - preferClearTypeAA = lf.lfQuality == CLEARTYPE_QUALITY; + LOGFONT lf = fontDefToLOGFONT(request); + const bool preferClearTypeAA = lf.lfQuality == CLEARTYPE_QUALITY; - hfont = CreateFontIndirect(&lf); - if (!hfont) - qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); + HFONT hfont = 0; + hfont = CreateFontIndirect(&lf); + if (!hfont) + qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); + + bool ttf = false; + int avWidth = 0; + BOOL res; + HGDIOBJ oldObj = SelectObject(data->hdc, hfont); + + TEXTMETRIC tm; + res = GetTextMetrics(data->hdc, &tm); + avWidth = tm.tmAveCharWidth; + ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE; + SelectObject(data->hdc, oldObj); + + if (!useDirectWrite) { + if (hfont && (!ttf || request.stretch != 100)) { + DeleteObject(hfont); + if (!res) + qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); + lf.lfWidth = avWidth * request.stretch/100; + hfont = CreateFontIndirect(&lf); + if (!hfont) + qErrnoWarning("%s: CreateFontIndirect with stretch failed", __FUNCTION__); + } - bool ttf = false; - int avWidth = 0; - BOOL res; - HGDIOBJ oldObj = SelectObject(data->hdc, hfont); + if (!hfont) + hfont = QWindowsFontDatabase::systemFont(); + } - TEXTMETRIC tm; - res = GetTextMetrics(data->hdc, &tm); - avWidth = tm.tmAveCharWidth; - ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE; - SelectObject(data->hdc, oldObj); +#if !defined(QT_NO_DIRECTWRITE) + else { + // Default to false for DirectWrite (and re-enable once/if everything turns out okay) + useDirectWrite = false; + if (initDirectWrite(data.data())) { + const QString fam = QString::fromWCharArray(lf.lfFaceName); + const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam); + if (nameSubstitute != fam) { + const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1); + memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t)); + lf.lfFaceName[nameSubstituteLength] = 0; + } - if (!useDirectWrite) { - if (hfont && (!ttf || request.stretch != 100)) { + HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT(&lf, &directWriteFont); + if (FAILED(hr)) { + qErrnoWarning("%s: CreateFontFromLOGFONT failed", __FUNCTION__); + } else { DeleteObject(hfont); - if (!res) - qErrnoWarning("QFontEngine::loadEngine: GetTextMetrics failed"); - lf.lfWidth = avWidth * request.stretch/100; - hfont = CreateFontIndirect(&lf); - if (!hfont) - qErrnoWarning("%s: CreateFontIndirect with stretch failed", __FUNCTION__); + useDirectWrite = true; } - - if (hfont == 0) - hfont = QWindowsFontDatabase::systemFont(); } - -#if !defined(QT_NO_DIRECTWRITE) - else { - // Default to false for DirectWrite (and re-enable once/if everything - // turns out okay) - useDirectWrite = false; - if (initDirectWrite(data.data())) { - const QString fam = QString::fromWCharArray(lf.lfFaceName); - const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam); - if (nameSubstitute != fam) { - const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1); - memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t)); - lf.lfFaceName[nameSubstituteLength] = 0; - } - - HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT( - &lf, - &directWriteFont); - if (FAILED(hr)) { - qErrnoWarning("%s: CreateFontFromLOGFONT failed", __FUNCTION__); - } else { - DeleteObject(hfont); - useDirectWrite = true; - } - } - } -#endif } +#endif QFontEngine *fe = 0; - if (!useDirectWrite) { + if (!useDirectWrite) { QWindowsFontEngine *few = new QWindowsFontEngine(request.family, hfont, lf, data); if (preferClearTypeAA) few->glyphFormat = QFontEngine::Format_A32; @@ -1760,10 +1749,10 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, } else { qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__); } - } - if (directWriteFont != 0) directWriteFont->Release(); + } + #endif return fe; -- cgit v1.2.3