diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-01-21 13:59:53 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-01-25 17:20:26 +0100 |
commit | 2e29a427ca2127ff7aff23049c65881d3c55bb40 (patch) | |
tree | f09cb266f5327a13ff916d16e7ea499f21dc3757 /src/gui/text/windows/qwindowsfontenginedirectwrite.cpp | |
parent | 78eac57f3dc788345f8f3e9b6dbd3dce70b8f511 (diff) |
Windows: Change default hinting preference for high-dpi
When high-dpi is enabled, we would previously default to
QFont::PreferVerticalHinting which maps to the asymmetric
antialiasing strategy, where only horizontal antialiasing is
enabled.
The idea behind this is that it provides crisper text,
especially for smaller font sizes, but for larger font sizes
the aliasing artifacts outweigh the added sharpness.
Inspecting native Windows applications, such as the system
settings, it looks like asymmetric antialiasing is used
up to a certain font size threshold. The documentation uses
a font size of 16 as the suggested threshold.
In accordance with the documentation, we use PreferNoHinting
for font sizes above this threshold.
[ChangeLog][Windows] When high-dpi scaling is active, the
default text antialiasing has been set to symmetric for
larger fonts (pixel size higher than 16 px). The old default
can be selected manually as QFont::PreferVerticalHinting.
Fixes: QTBUG-99066
Change-Id: Ibf53556f6e2cbbe1dc5d30c6c1743a499a99a90b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/text/windows/qwindowsfontenginedirectwrite.cpp')
-rw-r--r-- | src/gui/text/windows/qwindowsfontenginedirectwrite.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp index 55aab15132..5d4139f585 100644 --- a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp @@ -194,10 +194,16 @@ static DWRITE_MEASURING_MODE renderModeToMeasureMode(DWRITE_RENDERING_MODE rende } } -static DWRITE_RENDERING_MODE hintingPreferenceToRenderingMode(QFont::HintingPreference hintingPreference) +static DWRITE_RENDERING_MODE hintingPreferenceToRenderingMode(const QFontDef &fontDef) { - if (QHighDpiScaling::isActive() && hintingPreference == QFont::PreferDefaultHinting) - hintingPreference = QFont::PreferVerticalHinting; + QFont::HintingPreference hintingPreference = QFont::HintingPreference(fontDef.hintingPreference); + if (QHighDpiScaling::isActive() && hintingPreference == QFont::PreferDefaultHinting) { + // Microsoft documentation recommends using asymmetric rendering for small fonts + // at pixel size 16 and less, and symmetric for larger fonts. + hintingPreference = fontDef.pixelSize > 16.0 + ? QFont::PreferNoHinting + : QFont::PreferVerticalHinting; + } switch (hintingPreference) { case QFont::PreferNoHinting: @@ -507,7 +513,7 @@ void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEn QVarLengthArray<DWRITE_GLYPH_METRICS> glyphMetrics(glyphIndices.size()); HRESULT hr; - DWRITE_RENDERING_MODE renderMode = hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); + DWRITE_RENDERING_MODE renderMode = hintingPreferenceToRenderingMode(fontDef); if (renderMode == DWRITE_RENDERING_MODE_GDI_CLASSIC || renderMode == DWRITE_RENDERING_MODE_GDI_NATURAL) { hr = m_directWriteFontFace->GetGdiCompatibleGlyphMetrics(float(fontDef.pixelSize), 1.0f, @@ -686,8 +692,7 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, transform.m21 = xform.m21(); transform.m22 = xform.m22(); - DWRITE_RENDERING_MODE renderMode = - hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); + DWRITE_RENDERING_MODE renderMode = hintingPreferenceToRenderingMode(fontDef); DWRITE_MEASURING_MODE measureMode = renderModeToMeasureMode(renderMode); @@ -993,8 +998,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph transform.m21 = matrix.m21(); transform.m22 = matrix.m22(); - DWRITE_RENDERING_MODE renderMode = - hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); + DWRITE_RENDERING_MODE renderMode = hintingPreferenceToRenderingMode(fontDef); DWRITE_MEASURING_MODE measureMode = renderModeToMeasureMode(renderMode); IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; |