From 8a7db025ef113912a79363d43db4875af44fbabd Mon Sep 17 00:00:00 2001 From: Janus Thorborg Date: Sat, 3 Jan 2026 18:32:27 +0100 Subject: [PATCH] Direct2D: Effect revert of 14d5276 removing ClearType Antialiasing This adds Windows ClearType font antialiasing back as a disabled-by-default option "JUCE_ENABLE_DIRECT2D_CLEARTYPE_FONT_SMOOTHING" in the juce_graphics module. --- modules/juce_graphics/juce_graphics.h | 11 ++++++++++ .../native/juce_DirectX_windows.cpp | 21 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/juce_graphics/juce_graphics.h b/modules/juce_graphics/juce_graphics.h index 287c11873f..1b48a41127 100644 --- a/modules/juce_graphics/juce_graphics.h +++ b/modules/juce_graphics/juce_graphics.h @@ -87,6 +87,17 @@ #define JUCE_DISABLE_COREGRAPHICS_FONT_SMOOTHING 0 #endif +/** Config: JUCE_ENABLE_DIRECT2D_CLEARTYPE_FONT_SMOOTHING + + Setting this flag will *enable* Windows ClearType subpixel font antialiasing when using + the Direct2D renderer, if preferred by the end user. This is off by default due to + issues with transparency, certain compositions and transformations so make sure the + output looks acceptable for your use cases. +*/ +#ifndef JUCE_ENABLE_DIRECT2D_CLEARTYPE_FONT_SMOOTHING +#define JUCE_ENABLE_DIRECT2D_CLEARTYPE_FONT_SMOOTHING 0 +#endif + #ifndef JUCE_INCLUDE_PNGLIB_CODE #define JUCE_INCLUDE_PNGLIB_CODE 1 #endif diff --git a/modules/juce_graphics/native/juce_DirectX_windows.cpp b/modules/juce_graphics/native/juce_DirectX_windows.cpp index be8b59c7cc..f43371f092 100644 --- a/modules/juce_graphics/native/juce_DirectX_windows.cpp +++ b/modules/juce_graphics/native/juce_DirectX_windows.cpp @@ -270,7 +270,26 @@ ComSmartPtr Direct2DDeviceContext::create (ComSmartPtrSetTextAntialiasMode (D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE); +#if JUCE_ENABLE_DIRECT2D_CLEARTYPE_FONT_SMOOTHING + 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); +#else + result->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE); +#endif + result->SetAntialiasMode (D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); result->SetUnitMode (D2D1_UNIT_MODE_PIXELS);