wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
14.85k stars 676 forks source link

chinese punctuation position render too high up #5523

Open livexia opened 3 weeks ago

livexia commented 3 weeks ago

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

20240603-194616-e4b18c41

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

When displaying Chinese punctuation, the position of punctuation is high, e.g. commas are displayed in the middle of the line instead of at the bottom in general.

截屏2024-06-07 13 08 32

To Reproduce

No response

Configuration

local wezterm = require("wezterm")

local config = wezterm.config_builder()

config.window_decorations = "INTEGRATED_BUTTONS|RESIZE" config.enable_wayland = false config.front_end = "OpenGL"

config.window_padding = { left = "0.4cell", right = "0.3cell", top = "0.3cell", bottom = "0cell", }

config.font_size = 14.0 config.font = wezterm.font("FiraCode Nerd Font Mono")

config.color_scheme = "Argonaut (Gogh)" return config

Expected Behavior

iterm2:

截屏2024-06-07 13 09 11

alacritty:

截屏2024-06-07 13 09 39

Logs

No response

Anything else?

No response

jknockel commented 3 weeks ago

I believe that what you may be seeing is the Taiwanese CJK style. See here for an example. Because of Han unification (which was probably a mistake), a lot of different languages and dialects have characters/punctuation that share the same Unicode code points even though they are rendered differently in each language.

I believe you will have some luck using wezterm.font_with_fallback() in your config file to configure which CJK font you want to use as a fallback. For instance, if installed, you can use "Noto Sans CJK SC" for mainland Chinese style characters or "Noto Sans CJK TC" for Taiwanese style (among others).

I don't know if it is right or wrong to default to one style versus the other or what all of the variables are that could contribute to one default versus the other or if there is an easier way to configure this. On my system, I see mainland Chinese style characters by default, for instance.

livexia commented 3 weeks ago

Thanks, I think you are right, with wezterm ls-fonts --text "测试。," I get:

LeftToRight
 0 测    \u{6d4b}     x_adv=14 cells=2  glyph=4197 wezterm.font(".PingFang HK", {weight="Regular", stretch="Normal", style="Normal"})
                                      /System/Library/Fonts/PingFang.ttc index=18 variation=0, CoreText
 3 试    \u{8bd5}     x_adv=14 cells=2  glyph=6582 wezterm.font(".PingFang HK", {weight="Regular", stretch="Normal", style="Normal"})
                                      /System/Library/Fonts/PingFang.ttc index=18 variation=0, CoreText
 6 。    \u{3002}     x_adv=14 cells=2  glyph=29264 wezterm.font(".PingFang HK", {weight="Regular", stretch="Normal", style="Normal"})
                                      /System/Library/Fonts/PingFang.ttc index=18 variation=0, CoreText
 9 ,    \u{ff0c}     x_adv=14 cells=2  glyph=29287 wezterm.font(".PingFang HK", {weight="Regular", stretch="Normal", style="Normal"})
                                      /System/Library/Fonts/PingFang.ttc index=18 variation=0, CoreText

So wezterm using PingFang HK as default, but I still don't understand why it's using the wrong font, other terminal all using the right font.

livexia commented 3 weeks ago

After using PingFang SC as fallback font problem fixed. I don't know how this affect on system that doesn't have PingFang, also I think wezterm should be able to detect the default CJK font, so I will keep issue open.

jknockel commented 3 weeks ago

Do you know what variables affect this on Mac? On my linux machine, it looks like:

LC_ALL=zh_CN.UTF-8 gedit chinese.txt

gives me the mainland Chinese style and that

LC_ALL=zh_TW.UTF-8 gedit chinese.txt

gives me the Taiwanese style. Setting this environment variable works similarly if I replace gedit with xfce4-terminal and cat the file instead. But setting this environment variable seems to have no effect on which font wezterm uses.

livexia commented 3 weeks ago

there is a environment variable LANG on macos, I think there is also locale in mac. In iterm2 LANG=zh_CN.UTF-8 but in wezterm LANG=en_US.UTF-8 and there is only LC_CTYPE=UTF-8 in alacritty. I don't think the locale is the problem.

kenchou commented 2 weeks ago

https://wezfurlong.org/wezterm/config/lua/wezterm/font_with_fallback.html

I guess wezterm just searches for the first available font in order (wezterm ls-fonts --list-system), and it happens that PingFang HK is the first Chinese font. The correct approach for now is to use font_with_fallback to configure your preferred font list. As for automatically detecting the region and using the corresponding default font, it would be more complex and might be another topic.

我觉得 wezterm 只是按顺序(wezterm ls-fonts --list-system)查找第一个可用的字体,恰好 PingFang HK 是第一个中文字体而已。 目前正确的做法就是使用 font_with_fallback 配置自己的首选字体列表。至于自动检测地区使用对应的默认字体,会比较复杂,可能是另一个话题。

比如我的配置:

config.font = wezterm.font_with_fallback {
  'SauceCodePro Nerd Font',
  'JetBrains Mono',
  'Hack Nerd Font',
  'NotoSans Nerd Font',
  -- MacOS 默认的黑体。或者使用 'Noto Sans CJK SC' 也不错
  'Heiti SC',
}