retext icon indicating copy to clipboard operation
retext copied to clipboard

Problems of table editing mode about Chinese characters

Open theopathyreg opened this issue 3 years ago • 1 comments

When use table edit mode, there are some problems when input Chinese characters. because one Chinese character takes two letters space. Can't make the line fix together in edit window. I think that Japanese and some other characters should have the same problems. Really hope it can be fixed. Thank you. example

|      |     |     |
|------|-----|-----|
|你好    |     |     |
|你们好   |     |     |
|中文不能对齐|     |     |

theopathyreg avatar Oct 24 '22 11:10 theopathyreg

I took a look at this today. Here are some notes:

This problem happens not only with East Asian languages, but also with emojis, zero-width characters and more.

How much width a character takes depends on a font. Some fonts try to fit all characters into a single width, some fonts are duospaced.

To get a character width in a font, one can use QFontMetrics class (we are already using it for some other purposes). Also, Python has an east_asian_width function in the standard library which returns a code from this classifier.

The problem with the current table editing mode code (written by @Griffon26) is that Qt gives us only the number of added or removed characters, not their values or widths: https://github.com/retext-project/retext/blob/0987c28226714633a470b8b8a7ee89de9c7f6bc9/ReText/editor.py#L441

So to fix this issue one would need to rewrite this code to align cells without relying on information about added/removed lengths.

Pull requests for this are welcome. I am not sure if I will ever have time to rewrite this :(

mitya57 avatar Dec 18 '22 21:12 mitya57