Skip to content

Commit a413b4b

Browse files
arunjose696fedejeanne
authored andcommitted
Deprecate DefaultSWTFontRegistry and switch to ScalingSWTFontRegistry
1)Always use ScalingSWTFontRegistry 2)Rename DefaultSWTFontRegistry -> LegacySWTFontRegistry as this is not default anymore 3)Add a system property to use LegacySWTFontRegistry without monitor specific scaling active 4)Deprecate the LegacySWTFontRegistry(DefaultSWTFontRegistry)
1 parent de1f3ef commit a413b4b

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
import org.junit.jupiter.api.extension.*;
2424

2525
@ExtendWith(PlatformSpecificExecutionExtension.class)
26-
class DefaultSWTFontRegistryTests {
26+
class LegacySWTFontRegistryTests {
2727
private static String TEST_FONT = "Helvetica";
2828
private Display display;
2929
private SWTFontRegistry fontRegistry;
3030

31+
@SuppressWarnings("removal")
3132
@BeforeEach
3233
public void setUp() {
3334
this.display = Display.getDefault();
34-
this.fontRegistry = new DefaultSWTFontRegistry(display);
35+
this.fontRegistry = new LegacySWTFontRegistry(display);
3536
}
3637

3738
@AfterEach

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class ControlWin32Tests {
3333

3434
@Test
35-
public void testScaleFontCorrectlyInAutoScaleSzenario() {
35+
public void testScaleFontCorrectlyInAutoScaleScenario() {
3636
DPIUtil.setMonitorSpecificScaling(true);
3737
Display display = Display.getDefault();
3838

@@ -55,15 +55,37 @@ public void testSetFontWithMonitorSpecificScalingEnabled() {
5555
}
5656

5757
@Test
58-
public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario() {
58+
public void testScaleFontCorrectlyInNoAutoScaleScenario() {
5959
DPIUtil.setMonitorSpecificScaling(false);
6060
Display display = Display.getDefault();
6161

6262
assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime());
6363
int scalingFactor = 2;
6464
FontComparison fontComparison = updateFont(scalingFactor);
65-
assertEquals("Font height in pixels is different when setting the same font again",
66-
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
65+
assertEquals("Font height in pixels is not adjusted according to the scale factor",
66+
fontComparison.originalFontHeight * scalingFactor, fontComparison.currentFontHeight);
67+
}
68+
69+
@Test
70+
public void testDoNotScaleFontInNoAutoScaleScenarioWithLegacyFontRegistry() {
71+
DPIUtil.setMonitorSpecificScaling(false);
72+
String originalValue = System.getProperty("swt.fontRegistry");
73+
System.setProperty("swt.fontRegistry", "legacy");
74+
try {
75+
Display display = Display.getDefault();
76+
77+
assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime());
78+
int scalingFactor = 2;
79+
FontComparison fontComparison = updateFont(scalingFactor);
80+
assertEquals("Font height in pixels is different when setting the same font again",
81+
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
82+
} finally {
83+
if (originalValue != null) {
84+
System.setProperty("swt.fontRegistry", originalValue);
85+
} else {
86+
System.clearProperty("swt.fontRegistry");
87+
}
88+
}
6789
}
6890

6991
@Test

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DefaultSWTFontRegistry.java renamed to bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/LegacySWTFontRegistry.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@
1919
import org.eclipse.swt.internal.win32.*;
2020

2121
/**
22-
* This class is used in the win32 implementation only to support
23-
* unscaled fonts in multiple DPI zoom levels.
22+
* <p>
23+
* Formerly {@code DefaultSWTFontRegistry}, this class is deprecated. Use {@code ScalingSWTFontRegistry} instead.
24+
* To temporarily fall back to legacy font behavior ({@code LegacySWTFontRegistry})
25+
* (e.g., if issues arise in existing RCP products), set the system property: {@code
26+
* -Dswt.fontRegistry=legacy
27+
* }
28+
* </p>
2429
*
2530
* As this class is only intended to be used internally via {@code SWTFontProvider},
2631
* it should neither be instantiated nor referenced in a client application.
2732
* The behavior can change any time in a future release.
2833
*/
29-
final class DefaultSWTFontRegistry implements SWTFontRegistry {
34+
@Deprecated(forRemoval= true, since= "2025-09")
35+
final class LegacySWTFontRegistry implements SWTFontRegistry {
3036
private static FontData KEY_SYSTEM_FONTS = new FontData();
3137
private Map<FontData, Font> fontsMap = new HashMap<>();
3238
private Device device;
3339

34-
DefaultSWTFontRegistry(Device device) {
40+
LegacySWTFontRegistry(Device device) {
3541
this.device = device;
3642
}
3743

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ public static void disposeFontRegistry(Device device) {
105105
}
106106
}
107107

108+
private static final String SWT_FONT_REGISTRY = "swt.fontRegistry";
109+
110+
@SuppressWarnings("removal")
108111
private static SWTFontRegistry newFontRegistry(Device device) {
109-
if (device instanceof Display display && display.isRescalingAtRuntime()) {
110-
return new ScalingSWTFontRegistry(device);
112+
if ("legacy".equalsIgnoreCase(System.getProperty(SWT_FONT_REGISTRY)) && device instanceof Display display
113+
&& !display.isRescalingAtRuntime()) {
114+
return new LegacySWTFontRegistry(device);
111115
}
112-
return new DefaultSWTFontRegistry(device);
116+
return new ScalingSWTFontRegistry(device);
117+
113118
}
114119
}

0 commit comments

Comments
 (0)