Fix synthesized bold on Windows
There were a couple of problems with synthesizing boldness on Windows: For the DirectWrite font database, this was not implemented at all, so this change adds support for it. For the default GDI font database, the font engine is correctly created for a font with synthetic bold, but the function that retrieves the contours from the font does not apply the transformation. So when generating the distance fields for Qt Quick, we would get the unemboldened contours. The fix for this is simply to fall back to using DirectWrite for fonts that require any synthetization. This will later become the default anyway. Pick-to: 6.5 Fixes: QTBUG-119995 Change-Id: I5b4e3b19d0d71c6599746172da0bee41e8fb3940 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 05de036a8855adbdd882942d2fb61c231b02bf5a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 2243b815e06027f38da9c08aec7e43e8d1c85557) Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
parent
a599c69dc5
commit
30995a6e7c
@ -18,6 +18,32 @@ QT_BEGIN_NAMESPACE
|
||||
// Defined in gui/text/qfontdatabase.cpp
|
||||
Q_GUI_EXPORT QFontDatabase::WritingSystem qt_writing_system_for_script(int script);
|
||||
|
||||
template<typename T>
|
||||
struct DirectWriteScope {
|
||||
DirectWriteScope(T *res = nullptr) : m_res(res) {}
|
||||
~DirectWriteScope() {
|
||||
if (m_res != nullptr)
|
||||
m_res->Release();
|
||||
}
|
||||
|
||||
T **operator&()
|
||||
{
|
||||
return &m_res;
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return m_res;
|
||||
}
|
||||
|
||||
T *operator*() {
|
||||
return m_res;
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_res;
|
||||
};
|
||||
|
||||
QWindowsDirectWriteFontDatabase::QWindowsDirectWriteFontDatabase()
|
||||
{
|
||||
qCDebug(lcQpaFonts) << "Creating DirectWrite database";
|
||||
@ -217,6 +243,34 @@ QFontEngine *QWindowsDirectWriteFontDatabase::fontEngine(const QFontDef &fontDef
|
||||
IDWriteFontFace *face = reinterpret_cast<IDWriteFontFace *>(handle);
|
||||
Q_ASSERT(face != nullptr);
|
||||
|
||||
DWRITE_FONT_SIMULATIONS simulations = DWRITE_FONT_SIMULATIONS_NONE;
|
||||
if (fontDef.weight >= QFont::DemiBold || fontDef.style != QFont::StyleNormal) {
|
||||
DirectWriteScope<IDWriteFontFace3> face3;
|
||||
if (SUCCEEDED(face->QueryInterface(__uuidof(IDWriteFontFace3),
|
||||
reinterpret_cast<void **>(&face3)))) {
|
||||
if (fontDef.weight >= QFont::DemiBold && face3->GetWeight() < DWRITE_FONT_WEIGHT_DEMI_BOLD)
|
||||
simulations |= DWRITE_FONT_SIMULATIONS_BOLD;
|
||||
|
||||
if (fontDef.style != QFont::StyleNormal && face3->GetStyle() == DWRITE_FONT_STYLE_NORMAL)
|
||||
simulations |= DWRITE_FONT_SIMULATIONS_OBLIQUE;
|
||||
}
|
||||
}
|
||||
|
||||
DirectWriteScope<IDWriteFontFace5> newFace;
|
||||
if (simulations != DWRITE_FONT_SIMULATIONS_NONE) {
|
||||
DirectWriteScope<IDWriteFontFace5> face5;
|
||||
if (SUCCEEDED(face->QueryInterface(__uuidof(IDWriteFontFace5),
|
||||
reinterpret_cast<void **>(&face5)))) {
|
||||
DirectWriteScope<IDWriteFontResource> font;
|
||||
if (SUCCEEDED(face5->GetFontResource(&font))) {
|
||||
if (SUCCEEDED(font->CreateFontFace(simulations, nullptr, 0, &newFace)))
|
||||
face = *newFace;
|
||||
else
|
||||
qCWarning(lcQpaFonts) << "DirectWrite: Can't create font face for variable axis values";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWindowsFontEngineDirectWrite *fontEngine = new QWindowsFontEngineDirectWrite(face, fontDef.pixelSize, data());
|
||||
fontEngine->initFontInfo(fontDef, defaultVerticalDPI());
|
||||
|
||||
|
@ -1230,6 +1230,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
|
||||
HRESULT hr = data->directWriteGdiInterop->CreateFontFaceFromHdc(data->hdc, &directWriteFontFace);
|
||||
if (SUCCEEDED(hr)) {
|
||||
bool isColorFont = false;
|
||||
bool needsSimulation = false;
|
||||
#if QT_CONFIG(direct2d)
|
||||
IDWriteFontFace2 *directWriteFontFace2 = nullptr;
|
||||
if (SUCCEEDED(directWriteFontFace->QueryInterface(__uuidof(IDWriteFontFace2),
|
||||
@ -1237,10 +1238,12 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
|
||||
if (directWriteFontFace2->IsColorFont())
|
||||
isColorFont = directWriteFontFace2->GetPaletteEntryCount() > 0;
|
||||
|
||||
needsSimulation = directWriteFontFace2->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE;
|
||||
|
||||
directWriteFontFace2->Release();
|
||||
}
|
||||
#endif // direct2d
|
||||
useDw = useDw || useDirectWrite(hintingPreference, fam, isColorFont);
|
||||
useDw = useDw || useDirectWrite(hintingPreference, fam, isColorFont) || needsSimulation;
|
||||
qCDebug(lcQpaFonts)
|
||||
<< __FUNCTION__ << request.families.first() << request.pointSize << "pt"
|
||||
<< "hintingPreference=" << hintingPreference << "color=" << isColorFont
|
||||
|
Loading…
x
Reference in New Issue
Block a user