Skip to content

Commit 7f19dc5

Browse files
arunjose696HeikoKlare
authored andcommitted
[Win32] Do not set IME font if the font is disposed #2323
Prior to recent changes that ensure that a font handle is always retrieved via the SWTFontProvider, the hFont variable in Caret::setIMEFont was retrieved directly from the font object (using font.handle). Since those recent changes, hFont is fetched via SWTFontProvider, which throws an exception if the font is disposed. Previously, when the font was disposed, hFont (font.handle) would be zero, and the method would fall back to using defaultFont for setting the IME font. Now, this fallback no longer works because the exception is thrown before the fallback can occur. This commit restores the intended behavior by setting hFont as zero if the font is disposed, preventing the exception. Fixes #2323
1 parent e8aadbb commit 7f19dc5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public static long getFontHandle(Font font, int zoom) {
7474
if (font == null) {
7575
SWT.error(SWT.ERROR_NULL_ARGUMENT);
7676
}
77+
if (font.isDisposed()) {
78+
return 0;
79+
}
7780
return Font.win32_getHandle(getFont(font.getDevice(), font.getFontData()[0], zoom));
7881
}
7982

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
108108
font.dispose();
109109
}
110110

111+
@Test
112+
public void test_CaretWithDisposedFontDoesNotThrowException_issue2323() {
113+
Caret caret = new Caret(canvas, SWT.NONE);
114+
Font font = new Font(canvas.getDisplay(), "Default", 10, SWT.BOLD);
115+
shell.open();
116+
caret.setFont(font);
117+
font.dispose();
118+
canvas.setFocus();
119+
canvas.setCaret(caret);
120+
}
121+
111122
/* custom*/
112123
@Test
113124
public void test_consistency_MenuDetect() {

0 commit comments

Comments
 (0)