abrookins / WrapToColumn

An IntelliJ plugin that wraps text
Apache License 2.0
61 stars 12 forks source link

What can support Chinese? #5

Open ruchengtang opened 10 years ago

ruchengtang commented 10 years ago

I like this tool, but not support Chinese.

abrookins commented 10 years ago

Can you give me some example text, the expected output and the actual output, so I can debug this? I added a very simple test to demonstrate that Chinese is wrapped at the column width, but other than that, I'm not sure what the problem is. https://github.com/abrookins/WrapToColumn/blob/master/src/com/andrewbrookins/idea/wrap/CodeWrapperTest.java#L98

Thanks!

ruchengtang commented 10 years ago

wraptocolumn

achieve the effect of the picture as you can, usually used when writing Markdown or reStructuredText format documents.

test: 它是如何工作的呢?实际上,每个bundle在定义自己的服务配置都是跟目前为止你看到的是一样的。换句话说,一个bundle使用一个或者多个配置资源文件(通常是XML)来指定bundle所需要的参数和服务。然而,我们不直接在配置文件中使用 imports 命令导入它们,而是仅仅在bundle中调用一个服务容器扩展来为我们做同样的工作。一个服务容器扩展是 bundle 的作者创建的一个PHP类,它主要完成两件事情:

abrookins commented 10 years ago

Ah, yes, I see the problem now. The code is wrapping at 80 characters, but this doesn't account for the real size each code point takes up on the line. I will dig into this in my spare time.

abrookins commented 8 years ago

I looked into this problem more. Basically the font glyphs are variable-width, but Intellij's right margin guide (the visual bar) and the reflow algorithm in this plugin are based on monospaced characters.

Even though Intellij shows a right margin guide, it's positioned based on the width of a line of monospaced characters -- so Chinese glyphs are shown as spilling over the margin even if the characters, when considered as single-column width (i.e. monospace) are in total narrower than the right margin.

The only way I could think to wrap variable width text correctly would be to reflow it based on its display width (using something like Swing's FontMetrics) and the visual position of the right margin guide. That doesn't seem worth the effort to me, though I might pick it up again someday. Instead of doing that, I've added an explicit mention about variable width fonts to the README explaining that wrapping them probably won't work correctly.

abrookins commented 8 years ago

This is not as simple as I thought. Even while treating Chinese characters as taking a single column, the wrapping algorithm performs poorly because it considers only the space character as a word separator.