Skip to content

Commit 7f78dde

Browse files
committed
Ensure font is fetched from registry even when zoom levels match
The font returned by Font.win32_new is stored in the setFont() method of widgets. Previously, if targetZoom == font.zoom, the passed font was returned directly. However, the passed font could have been disposed by user code. This change ensures that the font is always fetched from the font registry, even when the zoom levels match, avoiding potential use of disposed fonts.
1 parent 7b46268 commit 7f78dde

File tree

1 file changed

+8
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+8
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public Font(Device device, FontData fd) {
105105
this.zoom = DPIUtil.getNativeDeviceZoom();
106106
this.fontData = new FontData(fd);
107107
this.fontHeight = fd.height;
108+
this.handle = SWTFontProvider.getFontHandle(this, this.zoom);
108109
init();
109110
}
110111

@@ -153,6 +154,7 @@ public Font(Device device, FontData[] fds) {
153154
FontData fd = fds[0];
154155
this.fontData = new FontData(fd);
155156
this.fontHeight = fd.height;
157+
this.handle = SWTFontProvider.getFontHandle(this, this.zoom);
156158
init();
157159
}
158160

@@ -186,9 +188,15 @@ public Font(Device device, String name, int height, int style) {
186188
this.zoom = DPIUtil.getNativeDeviceZoom();
187189
this.fontData = new FontData (name, height, style);
188190
this.fontHeight = height;
191+
this.handle = SWTFontProvider.getFontHandle(this, this.zoom);
189192
init();
190193
}
191194

195+
@Override
196+
void init() {
197+
super.init();
198+
}
199+
192200
@Override
193201
void destroy() {
194202
OS.DeleteObject(handle);
@@ -402,9 +410,6 @@ public static Font win32_new(Device device, FontData fontData, int zoom) {
402410
* @since 3.126
403411
*/
404412
public static Font win32_new(Font font, int targetZoom) {
405-
if (targetZoom == font.zoom) {
406-
return font;
407-
}
408413
return SWTFontProvider.getFont(font.getDevice(), font.getFontData()[0], targetZoom);
409414
}
410415
}

0 commit comments

Comments
 (0)