Skip to content
Closed
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,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class ControlWin32Tests {

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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -5805,7 +5805,7 @@ public Point textExtent (String string) {
* </ul>
*/
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,19 @@
import org.eclipse.swt.internal.win32.*;

/**
* <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>
* 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<FontData, Font> fontsMap = new HashMap<>();
private Device device;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading