Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class ControlWin32Tests {

@Test
public void testScaleFontCorrectlyInAutoScaleSzenario() {
public void testScaleFontCorrectlyInAutoScaleScenario() {
DPIUtil.setMonitorSpecificScaling(true);
Display display = Display.getDefault();

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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
* }
* </p>
*
* 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<FontData, Font> fontsMap = new HashMap<>();
private Device device;

DefaultSWTFontRegistry(Device device) {
LegacySWTFontRegistry(Device device) {
this.device = device;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ public static void disposeFontRegistry(Device device) {
}
}

private static final String SWT_FONT_REGISTRY = "swt.fontRegistry";

@SuppressWarnings("removal")
private static SWTFontRegistry newFontRegistry(Device device) {
if (device instanceof Display display && display.isRescalingAtRuntime()) {
return new ScalingSWTFontRegistry(device);
if ("legacy".equalsIgnoreCase(System.getProperty(SWT_FONT_REGISTRY)) && device instanceof Display display
&& !display.isRescalingAtRuntime()) {
return new LegacySWTFontRegistry(device);
}
return new DefaultSWTFontRegistry(device);
return new ScalingSWTFontRegistry(device);

}
}
Loading