eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
118 stars 137 forks source link

[win] Generic TextEditor: Some unicode characters cause text to be rendered incorrectly #1225

Open nlisker opened 5 months ago

nlisker commented 5 months ago

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: image (" abc ").

Copy the character (\u2B73).

  1. Paste it at the start of the string, the character is shown correctly, but the string changes its font: image
  2. Paste it at the end of the string, the character is shown incorrectly, but the string does not change font: image
  3. Copy a non-problematic character, like (\u2190). a. Paste it between and abc, the characters are shown correctly and the font does not change: image, image b. Paste it at the edge, and the problem resurfaces: image

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:

  1. Select the platform(s) on which the behavior is seen: Only tested on Windows.

      • [ ] All OS
      • [x] Windows
      • [ ] Linux
      • [ ] macOS
  2. Additional OS info (e.g. OS version, Linux Desktop, etc) Windows 10

  3. 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.

fedejeanne commented 5 months ago

@nlisker thank you for reporting this issue!

Is this something you would like to work on or were you just reporting it? :-)

nlisker commented 5 months ago

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.

jukzi commented 5 months ago

not reproducible with a plain org.eclipse.swt.custom.StyledText

jakub-suliga commented 4 months ago

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:

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. Screenshot 2024-06-12 112832

Image Explanation: For Example: D⭳ should be 8 + 5 = 13 and not 14.