[win] Generic TextEditor: Some unicode characters cause text to be rendered incorrectly
Describe the bug Redirected from Eclipse JDT: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1403
Adding some unicode characters to a text editor can cause either a change in the font of the line in which the character is added, or the character to not be displayed correctly.
To Reproduce
Open any text file in a text editor. My demonstration is with a .java file, but in the link above a .txt file is also used. Type text into that file, for example: (
" abc ").
Copy the character ⭳ (\u2B73).
- Paste it at the start of the string, the character is shown correctly, but the string changes its font:
- Paste it at the end of the string, the character is shown incorrectly, but the string does not change font:
- Copy a non-problematic character, like
←(\u2190). a. Paste it between⭳andabc, the characters are shown correctly and the font does not change:,
b. Paste it at the edge, and the problem resurfaces:
The same issue occurs with the character ⮠ (\u2BA0).
Expected behavior The characters will show correctly and the string will not change its font regardless of the positions those characters appear at.
Environment:
- Select the platform(s) on which the behavior is seen: Only tested on Windows.
-
- [ ] All OS
-
- [x] Windows
-
- [ ] Linux
-
- [ ] macOS
-
Additional OS info (e.g. OS version, Linux Desktop, etc) Windows 10
-
JRE/JDK version 21 and 22
Version since Eclipse 2024-03, haven't tested older versions. Text file encoding doesn't seem to matter. Tested UTF-8, UTF-16, UTF-16BE, UTF-16LE and ISO-8859-1.
@nlisker thank you for reporting this issue!
Is this something you would like to work on or were you just reporting it? :-)
Just reporting. I don't know SWT and the Eclipse inner workings well enough to be able to work on this in a meaningful amount of time.
not reproducible with a plain org.eclipse.swt.custom.StyledText
I was able to reproduce this issue with plain org.eclipse.swt.custom.StyledText. I used org.eclipse.swt.snippets.Snippet126 for testing and was able to replicate the bug. Here’s what I found:
- The width of the string unexpectedly changes when a Unicode character like ⭳ (\u2B73) is inserted after a single char. This leads incorrect display of the normal character (e.g. " ), either the normal char gets smaller or bigger.
- However, when the Unicode character is inserted after two or more characters, the width of the string remains constant and the character is displayed correctly.
I tested various positions and chars -> see image
The width of the text is set in the Method org.eclipse.swt.graphics.TextLayout.shape(long, StyleItem) on line 3897. It gets the width from the method OS.ScriptPlace.
There is probably somewhere a rounding error in the code.
I will test if the same problem occurs on Linux. When it works normally on Linux, it could be a Windows problem.
Image Explanation: For Example: D⭳ should be 8 + 5 = 13 and not 14.