From 74feaa5141df857cc3329373c50ff4a3e09ffbc5 Mon Sep 17 00:00:00 2001 From: arunjose696 Date: Tue, 5 Aug 2025 11:17:40 +0200 Subject: [PATCH 1/2] Revert Use font zoom in stringExtent and textExtent Fixes #2361 --- .../Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java index 4b0c478599..cd4f197b70 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java @@ -5725,7 +5725,7 @@ void apply() { */ public Point stringExtent (String string) { if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return Win32DPIUtils.pixelToPoint(drawable, stringExtentInPixels(string), data.font.zoom); + return Win32DPIUtils.pixelToPoint(drawable, stringExtentInPixels(string), getZoom()); } Point stringExtentInPixels (String string) { @@ -5805,7 +5805,7 @@ public Point textExtent (String string) { * */ public Point textExtent (String string, int flags) { - return Win32DPIUtils.pixelToPoint(drawable, textExtentInPixels(string, flags), data.font.zoom); + return Win32DPIUtils.pixelToPoint(drawable, textExtentInPixels(string, flags), getZoom()); } Point textExtentInPixels(String string, int flags) { From 08653e1e6cb7c8ffe76e70574d34d6738df1e9c6 Mon Sep 17 00:00:00 2001 From: arunjose696 Date: Wed, 6 Aug 2025 11:46:28 +0200 Subject: [PATCH 2/2] Revert "Deprecate DefaultSWTFontRegistry and switch to ScalingSWTFontRegistry" This reverts commit a413b4b7a52571c311aa333e4d7394b66f6b9a76. --- ....java => DefaultSWTFontRegistryTests.java} | 5 ++-- .../swt/widgets/ControlWin32Tests.java | 30 +++---------------- ...istry.java => DefaultSWTFontRegistry.java} | 14 +++------ .../eclipse/swt/internal/SWTFontProvider.java | 11 ++----- 4 files changed, 13 insertions(+), 47 deletions(-) rename bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/{LegacySWTFontRegistryTests.java => DefaultSWTFontRegistryTests.java} (96%) rename bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/{LegacySWTFontRegistry.java => DefaultSWTFontRegistry.java} (83%) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/LegacySWTFontRegistryTests.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DefaultSWTFontRegistryTests.java similarity index 96% rename from bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/LegacySWTFontRegistryTests.java rename to bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DefaultSWTFontRegistryTests.java index 80851f9b65..4dcaead797 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/LegacySWTFontRegistryTests.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/DefaultSWTFontRegistryTests.java @@ -23,16 +23,15 @@ import org.junit.jupiter.api.extension.*; @ExtendWith(PlatformSpecificExecutionExtension.class) -class LegacySWTFontRegistryTests { +class DefaultSWTFontRegistryTests { 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 LegacySWTFontRegistry(display); + this.fontRegistry = new DefaultSWTFontRegistry(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 3da919d191..a7b9c8de7c 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 @@ -35,7 +35,7 @@ class ControlWin32Tests { @Test - public void testScaleFontCorrectlyInAutoScaleScenario() { + public void testScaleFontCorrectlyInAutoScaleSzenario() { DPIUtil.setMonitorSpecificScaling(true); Display display = Display.getDefault(); @@ -58,37 +58,15 @@ public void testSetFontWithMonitorSpecificScalingEnabled() { } @Test - public void testScaleFontCorrectlyInNoAutoScaleScenario() { + public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario() { 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 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"); - } - } + assertEquals("Font height in pixels is different when setting the same font again", + fontComparison.originalFontHeight, fontComparison.currentFontHeight); } @Test diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java similarity index 83% rename from bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java rename to bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java index f1e287a4b0..222080e765 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java @@ -19,25 +19,19 @@ import org.eclipse.swt.internal.win32.*; /** - *

- * 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 - * } - *

+ * This class is used in the win32 implementation only to support + * unscaled fonts in multiple DPI zoom levels. * * 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. */ -@Deprecated(forRemoval= true, since= "2025-09") -final class LegacySWTFontRegistry implements SWTFontRegistry { +final class DefaultSWTFontRegistry implements SWTFontRegistry { private static FontData KEY_SYSTEM_FONTS = new FontData(); private Map fontsMap = new HashMap<>(); private Device device; - LegacySWTFontRegistry(Device device) { + DefaultSWTFontRegistry(Device device) { this.device = device; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java index 7312a5acb2..6addde3c98 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java @@ -108,15 +108,10 @@ public static void disposeFontRegistry(Device device) { } } - private static final String SWT_FONT_REGISTRY = "swt.fontRegistry"; - - @SuppressWarnings("removal") private static SWTFontRegistry newFontRegistry(Device device) { - if ("legacy".equalsIgnoreCase(System.getProperty(SWT_FONT_REGISTRY)) && device instanceof Display display - && !display.isRescalingAtRuntime()) { - return new LegacySWTFontRegistry(device); + if (device instanceof Display display && display.isRescalingAtRuntime()) { + return new ScalingSWTFontRegistry(device); } - return new ScalingSWTFontRegistry(device); - + return new DefaultSWTFontRegistry(device); } }