ITADN

StyledText: Japanese characters not drawn correctly when adding numbers in front of the text

#3266Opentueterich 创建于 2026-04-23
T
tueterichcommented
When using the StyledText Widget with a custom set font and inserting numbers in front of an existing japanese text, the japanese characters will sometimes bug out and will not be drawn correctly. I am not able to reproduce it every time I execute the snippet, but every 4th time or so the bug will happen. I could reproduce this problem with the following fonts: Arial Roboto Times New Roman Noto Sans This will not happen if "StyledText#setFont()" was not called. Also, inserting numbers anywhere but at the beginning will also work just fine. **To reproduce** Use the following snippet and try settings different fonts. Focus the StyledText and insert "11" (or any two numbers) in front of the japanese characters. ``` import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class StyledTextJpnSnippet { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); StyledText text = new StyledText(shell, SWT.BORDER | SWT.SINGLE | SWT.LEAD); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); text.setText("ありがとうございます"); text.setFont(new Font(display, "Times New Roman", 12, SWT.NORMAL)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } ``` **Expected behavior** Sometimes the japanese character will not be drawn correctly. Depending on the font, they will be drawn as crossed-out blocks or straight lines. **Screenshots** <img width="189" height="68" alt="Image" src="https://github.com/user-attachments/assets/f7fb2159-b784-498e-8a39-eacc152a4614" /> <img width="138" height="47" alt="Image" src="https://github.com/user-attachments/assets/af8577c6-a117-4eb7-81ee-72bb907353e5" /> <img width="174" height="47" alt="Image" src="https://github.com/user-attachments/assets/39ee651e-c4e7-4e4d-a247-2255128bdd73" /> **Environment:** 1. Select the platform(s) on which the behavior is seen: - - [] All OS - - [x] Windows - - [ ] Linux - - [ ] macOS 2. Additional OS info (e.g. OS version, Linux Desktop, etc) - Windows 11 Pro 25H2 3. JRE/JDK version Tested on both Oracle JDK 1.8u131 and Amazon Corretto 21.07_6 **Version since** Since version 4.919, but tested also on 4.972 [SWT 4.39] **Workaround (or) Additional context** No workarounds except restarting the snippet / client.
3 条评论