Skip to content

Commit 32b21db

Browse files
committed
Caching systemFont as well
1 parent 9e63122 commit 32b21db

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void testScaleFontCorrectlyInNoAutoScaleSzenario() {
4848
DPIUtil.setMonitorSpecificScaling(false);
4949
Display display = Display.getDefault();
5050

51-
assertTrue("Autoscale property is not set to true", display.isRescalingAtRuntime());
51+
assertFalse("Autoscale property is not set to true", display.isRescalingAtRuntime());
5252
int scalingFactor = 2;
5353
FontComparison fontComparison = updateFont(scalingFactor);
5454
assertEquals("Font height in pixels is not adjusted according to the scale factor",
@@ -58,14 +58,27 @@ public void testScaleFontCorrectlyInNoAutoScaleSzenario() {
5858
@Test
5959
public void testDoNotScaleFontCorrectlyInNoAutoScaleSzenarioWithLegacyFontRegistry() {
6060
DPIUtil.setMonitorSpecificScaling(false);
61+
String originalValue = System.getProperty("swt.fontRegistry");
6162
System.setProperty("swt.fontRegistry", "LEGACY");
62-
Display display = Display.getDefault();
63+
try {
64+
Display display = Display.getDefault();
65+
66+
assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime());
67+
int scalingFactor = 2;
68+
FontComparison fontComparison = updateFont(scalingFactor);
69+
assertEquals("Font height in pixels is different when setting the same font again",
70+
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
71+
72+
73+
}
74+
finally {
75+
if (originalValue != null) {
76+
System.setProperty("swt.fontRegistry", originalValue);
77+
} else {
78+
System.clearProperty("swt.fontRegistry");
79+
}
80+
}
6381

64-
assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime());
65-
int scalingFactor = 2;
66-
FontComparison fontComparison = updateFont(scalingFactor);
67-
assertEquals("Font height in pixels is different when setting the same font again",
68-
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
6982
}
7083

7184
@Test

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ private class ScaledSystemFontContainer extends ScaledFontContainer {
7878
@Override
7979
protected Font createFont(int zoom) {
8080
long newHandle = createSystemFontHandle(zoom);
81-
return Font.win32_new(device, newHandle, zoom);
81+
82+
Font systemFont = Font.win32_new(device, newHandle, zoom);
83+
FontData clonedFontData = systemFont.getFontData()[0];
84+
if (!customFontsKeyMap.containsKey(clonedFontData)) {
85+
customFontsKeyMap.put(clonedFontData, systemFontContainer);
86+
}
87+
return systemFont;
8288
}
8389

8490
private long createSystemFontHandle(int zoom) {

0 commit comments

Comments
 (0)