From 90963387e455900cceea2570f8906b3e3243bd17 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 13 Feb 2024 13:24:15 +0100 Subject: [PATCH] Fix kerning errors when using DirectWrite backend There were a couple of errors when calculating advances in the DirectWrite font engine: First of all, we would apply the CLEARTYPE_NATURAL glyph metrics when using GDI_CLASSIC rendering, causing text to look compressed in some places, because we always passed TRUE for the useGdiNatural parameter to GetGdiCompatibleGlyphMetrics(). In addition, we would pick the GDI-compatible metrics even when design metrics had explicitly been requested on the layout. This is the case for distance field rendered text, which always operates with design metrics and scalable layouts, so it was visible as kerning errors on some text there. Pick-to: 6.6 6.5 Fixes: QTBUG-122139 Fixes: QTBUG-122167 Change-Id: Ic28da6b3235d7af0452bdcb836e037594f8a20ba Reviewed-by: Konstantin Ritt (cherry picked from commit de3d5dd73b748bc1591447fe81dff6427a86f77b) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/windows/qwindowsfontenginedirectwrite.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp index e5a2c7a2b83..8027825b036 100644 --- a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp @@ -471,7 +471,7 @@ QFontEngine::FaceId QWindowsFontEngineDirectWrite::faceId() const return m_faceId; } -void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags) const +void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags shaperFlags) const { QVarLengthArray glyphIndices(glyphs->numGlyphs); @@ -483,11 +483,13 @@ void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEn HRESULT hr; DWRITE_RENDERING_MODE renderMode = hintingPreferenceToRenderingMode(fontDef); - if (renderMode == DWRITE_RENDERING_MODE_GDI_CLASSIC || renderMode == DWRITE_RENDERING_MODE_GDI_NATURAL) { + bool needsDesignMetrics = shaperFlags & QFontEngine::DesignMetrics; + if (!needsDesignMetrics && (renderMode == DWRITE_RENDERING_MODE_GDI_CLASSIC + || renderMode == DWRITE_RENDERING_MODE_GDI_NATURAL)) { hr = m_directWriteFontFace->GetGdiCompatibleGlyphMetrics(float(fontDef.pixelSize), 1.0f, NULL, - TRUE, + renderMode == DWRITE_RENDERING_MODE_GDI_NATURAL, glyphIndices.data(), glyphIndices.size(), glyphMetrics.data());