From b12088a1f6a405d4ee85f0f2c43afb0babd8a46f Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 23 Aug 2024 12:27:30 +0100 Subject: [PATCH] Direct2D: Match system preferences for text antialiasing --- .../juce_graphics/native/juce_DirectX_windows.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/juce_graphics/native/juce_DirectX_windows.h b/modules/juce_graphics/native/juce_DirectX_windows.h index a4b72466dc..720b0bd8b4 100644 --- a/modules/juce_graphics/native/juce_DirectX_windows.h +++ b/modules/juce_graphics/native/juce_DirectX_windows.h @@ -348,7 +348,21 @@ struct Direct2DDeviceContext return {}; } - result->SetTextAntialiasMode (D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE); + const auto textAntialiasing = [&] + { + BOOL smoothingEnabled{}; + SystemParametersInfo (SPI_GETFONTSMOOTHING, 0, &smoothingEnabled, 0); + + if (! smoothingEnabled) + return D2D1_TEXT_ANTIALIAS_MODE_ALIASED; + + UINT smoothingKind{}; + SystemParametersInfo (SPI_GETFONTSMOOTHINGTYPE, 0, &smoothingKind, 0); + return smoothingKind == FE_FONTSMOOTHINGCLEARTYPE ? D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE + : D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE; + }(); + + result->SetTextAntialiasMode (textAntialiasing); result->SetAntialiasMode (D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); result->SetUnitMode (D2D1_UNIT_MODE_PIXELS);