Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems of table editing mode about Chinese characters #598

Open
theopathyreg opened this issue Oct 24, 2022 · 1 comment
Open

Problems of table editing mode about Chinese characters #598

theopathyreg opened this issue Oct 24, 2022 · 1 comment

Comments

@theopathyreg
Copy link

theopathyreg commented Oct 24, 2022

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 theopathyreg changed the title Problems of table edit mode about Chinese characters Problems of table editing mode about Chinese characters Oct 25, 2022
@mitya57
Copy link
Member

mitya57 commented Dec 18, 2022

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:

tablemode.adjustTableToChanges(self.document(), pos, added - removed, markupClass)

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 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants