File tree Expand file tree Collapse file tree 4 files changed +51
-10
lines changed
Eclipse SWT Tests/win32/org/eclipse/swt
Eclipse SWT/win32/org/eclipse/swt/internal Expand file tree Collapse file tree 4 files changed +51
-10
lines changed Original file line number Diff line number Diff line change 2323import 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
Original file line number Diff line number Diff line change @@ -44,10 +44,23 @@ public void testScaleFontCorrectlyInAutoScaleSzenario() {
4444 }
4545
4646 @ Test
47- public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenario () {
47+ public void testScaleFontCorrectlyInNoAutoScaleSzenario () {
4848 DPIUtil .setMonitorSpecificScaling (false );
4949 Display display = Display .getDefault ();
5050
51+ assertTrue ("Autoscale property is not set to true" , display .isRescalingAtRuntime ());
52+ int scalingFactor = 2 ;
53+ FontComparison fontComparison = updateFont (scalingFactor );
54+ assertEquals ("Font height in pixels is not adjusted according to the scale factor" ,
55+ fontComparison .originalFontHeight * scalingFactor , fontComparison .currentFontHeight );
56+ }
57+
58+ @ Test
59+ public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenarioWithLegacyFontRegistry () {
60+ DPIUtil .setMonitorSpecificScaling (false );
61+ System .setProperty ("swt.fontRegistry" , "LEGACY" );
62+ Display display = Display .getDefault ();
63+
5164 assertFalse ("Autoscale property is not set to false" , display .isRescalingAtRuntime ());
5265 int scalingFactor = 2 ;
5366 FontComparison fontComparison = updateFont (scalingFactor );
Original file line number Diff line number Diff line change 1919import 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
Original file line number Diff line number Diff line change @@ -105,10 +105,32 @@ 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+
108126 private static SWTFontRegistry newFontRegistry (Device device ) {
109- if (device instanceof Display display && display .isRescalingAtRuntime ()) {
110- return new ScalingSWTFontRegistry (device );
127+ String registryProp = System .getProperty (SWT_FONT_REGISTRY );
128+ FontRegistryType fontRegistryValue = FontRegistryType .fromString (registryProp );
129+ if (fontRegistryValue == FontRegistryType .LEGACY && device instanceof Display display
130+ && !display .isRescalingAtRuntime ()) {
131+ return new LegacySWTFontRegistry (device );
111132 }
112- return new DefaultSWTFontRegistry (device );
133+ return new ScalingSWTFontRegistry (device );
134+
113135 }
114136}
You can’t perform that action at this time.
0 commit comments