[QWindowsFontDatabase] Move code around to improve readability
Keep DirectWrite initialization code in a single place and fallback to GDI implementation if DirectWrite initialization has failed. Change-Id: I2da185dbc073c58a7ba47bae09957ecac877d712 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
4d54fe8d02
commit
a2ebd502d4
@ -1682,13 +1682,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request,
|
|||||||
int dpi,
|
int dpi,
|
||||||
const QSharedPointer<QWindowsFontEngineData> &data)
|
const QSharedPointer<QWindowsFontEngineData> &data)
|
||||||
{
|
{
|
||||||
#if !defined(QT_NO_DIRECTWRITE)
|
QFontEngine *fe = 0;
|
||||||
bool useDirectWrite = (request.hintingPreference == QFont::PreferNoHinting)
|
|
||||||
|| (request.hintingPreference == QFont::PreferVerticalHinting);
|
|
||||||
IDWriteFont *directWriteFont = 0;
|
|
||||||
#else
|
|
||||||
bool useDirectWrite = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LOGFONT lf = fontDefToLOGFONT(request);
|
LOGFONT lf = fontDefToLOGFONT(request);
|
||||||
const bool preferClearTypeAA = lf.lfQuality == CLEARTYPE_QUALITY;
|
const bool preferClearTypeAA = lf.lfQuality == CLEARTYPE_QUALITY;
|
||||||
@ -1712,29 +1706,40 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(QT_NO_DIRECTWRITE)
|
#if !defined(QT_NO_DIRECTWRITE)
|
||||||
if (useDirectWrite) {
|
bool useDirectWrite = (request.hintingPreference == QFont::PreferNoHinting)
|
||||||
// Default to false for DirectWrite (and re-enable once/if everything turns out okay)
|
|| (request.hintingPreference == QFont::PreferVerticalHinting);
|
||||||
useDirectWrite = false;
|
if (useDirectWrite && initDirectWrite(data.data())) {
|
||||||
if (initDirectWrite(data.data())) {
|
const QString fam = QString::fromWCharArray(lf.lfFaceName);
|
||||||
const QString fam = QString::fromWCharArray(lf.lfFaceName);
|
const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam);
|
||||||
const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam);
|
if (nameSubstitute != fam) {
|
||||||
if (nameSubstitute != fam) {
|
const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1);
|
||||||
const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1);
|
memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t));
|
||||||
memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t));
|
lf.lfFaceName[nameSubstituteLength] = 0;
|
||||||
lf.lfFaceName[nameSubstituteLength] = 0;
|
}
|
||||||
|
|
||||||
|
IDWriteFont *directWriteFont = 0;
|
||||||
|
HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT(&lf, &directWriteFont);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
qErrnoWarning("%s: CreateFontFromLOGFONT failed", __FUNCTION__);
|
||||||
|
} else {
|
||||||
|
IDWriteFontFace *directWriteFontFace = NULL;
|
||||||
|
hr = directWriteFont->CreateFontFace(&directWriteFontFace);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__);
|
||||||
|
} else {
|
||||||
|
QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace,
|
||||||
|
request.pixelSize,
|
||||||
|
data);
|
||||||
|
fedw->initFontInfo(request, dpi, directWriteFont);
|
||||||
|
fe = fedw;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT(&lf, &directWriteFont);
|
directWriteFont->Release();
|
||||||
if (FAILED(hr))
|
|
||||||
qErrnoWarning("%s: CreateFontFromLOGFONT failed", __FUNCTION__);
|
|
||||||
else
|
|
||||||
useDirectWrite = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // QT_NO_DIRECTWRITE
|
||||||
|
|
||||||
QFontEngine *fe = 0;
|
if (!fe) {
|
||||||
if (!useDirectWrite) {
|
|
||||||
QWindowsFontEngine *few = new QWindowsFontEngine(request.family, lf, data);
|
QWindowsFontEngine *few = new QWindowsFontEngine(request.family, lf, data);
|
||||||
if (preferClearTypeAA)
|
if (preferClearTypeAA)
|
||||||
few->glyphFormat = QFontEngine::Format_A32;
|
few->glyphFormat = QFontEngine::Format_A32;
|
||||||
@ -1742,25 +1747,6 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request,
|
|||||||
fe = few;
|
fe = few;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(QT_NO_DIRECTWRITE)
|
|
||||||
else {
|
|
||||||
IDWriteFontFace *directWriteFontFace = NULL;
|
|
||||||
HRESULT hr = directWriteFont->CreateFontFace(&directWriteFontFace);
|
|
||||||
if (SUCCEEDED(hr)) {
|
|
||||||
QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace,
|
|
||||||
request.pixelSize,
|
|
||||||
data);
|
|
||||||
fedw->initFontInfo(request, dpi, directWriteFont);
|
|
||||||
fe = fedw;
|
|
||||||
} else {
|
|
||||||
qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__);
|
|
||||||
}
|
|
||||||
|
|
||||||
directWriteFont->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return fe;
|
return fe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user