Skip to content

Commit 3241eaf

Browse files
arunjose696arunjose696
authored andcommitted
Deprecate DefaultSWTFontRegistry and Completely 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 3)Deprecate the LegacySWTFontRegistry(DefaultSWTFontRegistry)
1 parent 31da941 commit 3241eaf

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
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

3131
@BeforeEach
3232
public void setUp() {
3333
this.display = Display.getDefault();
34-
this.fontRegistry = new DefaultSWTFontRegistry(display);
34+
this.fontRegistry = new LegacySWTFontRegistry(display);
3535
}
3636

3737
@AfterEach
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@
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>This class was formerly referred to as {@code DefaultSWTFontRegistry}, it is now selected
23+
* via the {@code FontRegistryType.LEGACY} setting, which can be configured using
24+
* the system property {@code swt.fontRegistry}.</p>
2425
*
2526
* As this class is only intended to be used internally via {@code SWTFontProvider},
2627
* it should neither be instantiated nor referenced in a client application.
2728
* The behavior can change any time in a future release.
2829
*/
29-
final class DefaultSWTFontRegistry implements SWTFontRegistry {
30+
@Deprecated(forRemoval= true, since= "2025-09")
31+
final class LegacySWTFontRegistry implements SWTFontRegistry {
3032
private static FontData KEY_SYSTEM_FONTS = new FontData();
3133
private Map<FontData, Font> fontsMap = new HashMap<>();
3234
private Device device;
3335

34-
DefaultSWTFontRegistry(Device device) {
36+
LegacySWTFontRegistry(Device device) {
3537
this.device = device;
3638
}
3739

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

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

108+
private static enum FontRegistryType {
109+
LEGACY, SCALING;
110+
111+
public static FontRegistryType fromString(String s) {
112+
if (s == null) {
113+
return SCALING;
114+
}
115+
for (FontRegistryType type : values()) {
116+
if (type.name().equalsIgnoreCase(s)) {
117+
return type;
118+
}
119+
}
120+
return SCALING; // fallback to default if invalid
121+
}
122+
}
123+
124+
private static final String SWT_FONT_REGISTRY = "swt.fontRegistry";
125+
private static final FontRegistryType fontRegistryValue;
126+
static {
127+
String registryProp = System.getProperty(SWT_FONT_REGISTRY);
128+
fontRegistryValue = FontRegistryType.fromString(registryProp);
129+
}
130+
108131
private static SWTFontRegistry newFontRegistry(Device device) {
109-
if (device instanceof Display display && display.isRescalingAtRuntime()) {
110-
return new ScalingSWTFontRegistry(device);
132+
if (fontRegistryValue == FontRegistryType.LEGACY && device instanceof Display display
133+
&& !display.isRescalingAtRuntime()) {
134+
return new LegacySWTFontRegistry(device);
111135
}
112-
return new DefaultSWTFontRegistry(device);
136+
return new ScalingSWTFontRegistry(device);
137+
113138
}
114139
}

0 commit comments

Comments
 (0)