diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DefaultSWTFontRegistryTests.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/LegacySWTFontRegistryTests.java similarity index 96% rename from bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DefaultSWTFontRegistryTests.java rename to bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/LegacySWTFontRegistryTests.java index 4dcaead797c..80851f9b653 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DefaultSWTFontRegistryTests.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/LegacySWTFontRegistryTests.java @@ -23,15 +23,16 @@ import org.junit.jupiter.api.extension.*; @ExtendWith(PlatformSpecificExecutionExtension.class) -class DefaultSWTFontRegistryTests { +class LegacySWTFontRegistryTests { private static String TEST_FONT = "Helvetica"; private Display display; private SWTFontRegistry fontRegistry; + @SuppressWarnings("removal") @BeforeEach public void setUp() { this.display = Display.getDefault(); - this.fontRegistry = new DefaultSWTFontRegistry(display); + this.fontRegistry = new LegacySWTFontRegistry(display); } @AfterEach diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java index ab56cc9bf49..7926fb9e16c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java @@ -32,7 +32,7 @@ class ControlWin32Tests { @Test - public void testScaleFontCorrectlyInAutoScaleSzenario() { + public void testScaleFontCorrectlyInAutoScaleScenario() { DPIUtil.setMonitorSpecificScaling(true); Display display = Display.getDefault(); @@ -55,15 +55,37 @@ public void testSetFontWithMonitorSpecificScalingEnabled() { } @Test - public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario() { + public void testScaleFontCorrectlyInNoAutoScaleScenario() { DPIUtil.setMonitorSpecificScaling(false); Display display = Display.getDefault(); assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime()); int scalingFactor = 2; FontComparison fontComparison = updateFont(scalingFactor); - assertEquals("Font height in pixels is different when setting the same font again", - fontComparison.originalFontHeight, fontComparison.currentFontHeight); + assertEquals("Font height in pixels is not adjusted according to the scale factor", + fontComparison.originalFontHeight * scalingFactor, fontComparison.currentFontHeight); + } + + @Test + public void testDoNotScaleFontInNoAutoScaleScenarioWithLegacyFontRegistry() { + DPIUtil.setMonitorSpecificScaling(false); + String originalValue = System.getProperty("swt.fontRegistry"); + System.setProperty("swt.fontRegistry", "legacy"); + try { + Display display = Display.getDefault(); + + assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime()); + int scalingFactor = 2; + FontComparison fontComparison = updateFont(scalingFactor); + assertEquals("Font height in pixels is different when setting the same font again", + fontComparison.originalFontHeight, fontComparison.currentFontHeight); + } finally { + if (originalValue != null) { + System.setProperty("swt.fontRegistry", originalValue); + } else { + System.clearProperty("swt.fontRegistry"); + } + } } @Test diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java similarity index 83% rename from bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java rename to bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java index 222080e765b..f1e287a4b00 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java @@ -19,19 +19,25 @@ import org.eclipse.swt.internal.win32.*; /** - * This class is used in the win32 implementation only to support - * unscaled fonts in multiple DPI zoom levels. + *
+ * Formerly {@code DefaultSWTFontRegistry}, this class is deprecated. Use {@code ScalingSWTFontRegistry} instead. + * To temporarily fall back to legacy font behavior ({@code LegacySWTFontRegistry}) + * (e.g., if issues arise in existing RCP products), set the system property: {@code + * -Dswt.fontRegistry=legacy + * } + *
* * As this class is only intended to be used internally via {@code SWTFontProvider}, * it should neither be instantiated nor referenced in a client application. * The behavior can change any time in a future release. */ -final class DefaultSWTFontRegistry implements SWTFontRegistry { +@Deprecated(forRemoval= true, since= "2025-09") +final class LegacySWTFontRegistry implements SWTFontRegistry { private static FontData KEY_SYSTEM_FONTS = new FontData(); private Map