charmbracelet / freeze

Generate images of code and terminal output 📸
MIT License
3.24k stars 55 forks source link

The Chinese in the picture is garbled #93

Open yihanglee-cn opened 4 months ago

yihanglee-cn commented 4 months ago

Describe the bug The Chinese in the code is garbled when I generate picture in Windows11.

To Reproduce Steps to reproduce the behavior:

  1. Excute: freeze GetAppStartupTime.py -o GetAppStartupTime.png
  2. There are Chinese in code
  3. The Chinese in the picture is garbled

Expected behavior Chinese is display normally

Screenshots image

Desktop (please complete the following information):

AlejandroSuero commented 4 months ago

image using freeze

Image from wezterm configuration

Same issue as @yihanglee-cn running on MacOS 14.4.1.

As you can see when using the same font in wezterm, it prints the characters correctly.

wangdaming261 commented 4 months ago

需要换字体,换个字体就好了

yihanglee-cn commented 4 months ago

需要换字体,换个字体就好了

你是怎么改字体的呀,我试了下面几个方案都不行

freeze -c custom.json GetAppStartupTime.py -o GetAppStartupTime2.png
freeze --font.family "LXGW WenKai GB Screen" GetAppStartupTime.py -o GetAppStartupTime4.png
freeze --font.file  "LXGWWenKaiGBScreen.ttf" GetAppStartupTime.py -o GetAppStartupTime4.png
AlejandroSuero commented 4 months ago

@yihanglee-cn I also tried changing it the font like that, I thinks it needs the full path but I haven't checked it yet.

yihanglee-cn commented 4 months ago

@yihanglee-cn I also tried changing it the font like that, I thinks it needs the full path but I haven't checked it yet.我也尝试像那样更改字体,我认为它需要完整的路径,但我还没有检查它。

Waiting for your good news😁

wangdaming261 commented 4 months ago

估计有bug,你不换字体输出文件是svg能显示中文,png字体就算用绝对路径也不显示中文 image image

wangdaming261 commented 4 months ago

需要换字体,换个字体就好了

你是怎么改字体的呀,我试了下面几个方案都不行

freeze -c custom.json GetAppStartupTime.py -o GetAppStartupTime2.png
freeze --font.family "LXGW WenKai GB Screen" GetAppStartupTime.py -o GetAppStartupTime4.png
freeze --font.file  "LXGWWenKaiGBScreen.ttf" GetAppStartupTime.py -o GetAppStartupTime4.png

我刚才说的不对,我仔细看了下。这程序是生成svg再转成png,自定义字体文件需要--font.family "WenQuanYi Zen Hei Mono" --font.file WenQuanYi_Zen_Hei_Mono.ttf一块用,但是在转png的时候也就是png.go,好像没有加载自定义的字体文件

err = fontdb.LoadFontData(font.JetBrainsMonoTTF)
if err != nil {
    printErrorFatal("Unable to load font", err)
}
err = fontdb.LoadFontData(font.JetBrainsMonoNLTTF)
if err != nil {
    printErrorFatal("Unable to load font", err)
}

如果你着急用的话,就把front/font.go下的//go:embed开头改下你需要的字体,然后编译后执行 ./freeze --font.family "WenQuanYi Zen Hei Mono" a.txt -o c.png 就显示中文,我测试WenQuanYi Zen Hei Mono字体是支持中文的,导出png显示正常。

yihanglee-cn commented 4 months ago

需要换字体,换个字体就好了

你是怎么改字体的呀,我试了下面几个方案都不行

freeze -c custom.json GetAppStartupTime.py -o GetAppStartupTime2.png
freeze --font.family "LXGW WenKai GB Screen" GetAppStartupTime.py -o GetAppStartupTime4.png
freeze --font.file  "LXGWWenKaiGBScreen.ttf" GetAppStartupTime.py -o GetAppStartupTime4.png

我找到原因了,这程序是先生成svg再转成png,生成的svg中有一项font-family属性写死成font-family="JetBrains Mono" 就导致svg转png那程序还是用JetBrains Mono字体解析的 image

厉害👍,那只能等修复了。

kamiertop commented 2 months ago

需要换字体,换个字体就好了

你是怎么改字体的呀,我试了下面几个方案都不行

freeze -c custom.json GetAppStartupTime.py -o GetAppStartupTime2.png
freeze --font.family "LXGW WenKai GB Screen" GetAppStartupTime.py -o GetAppStartupTime4.png
freeze --font.file  "LXGWWenKaiGBScreen.ttf" GetAppStartupTime.py -o GetAppStartupTime4.png

我找到原因了,这程序是先生成svg再转成png,生成的svg中有一项font-family属性写死成font-family="JetBrains Mono" 就导致svg转png那程序还是用JetBrains Mono字体解析的 image

厉害👍,那只能等修复了。

我在font文件夹中增加了支持中文的字体文件MeowSans.ttf, 然后在font.go增加了:

//go:embed MeowSans.ttf
var MeowSansTTF []byte

png.go增加了:

if err = fontdb.LoadFontData(font.MeowSansTTF); err != nil {
      printErrorFatal("Unable to load font", err)
}

重新编译执行即可看到正常渲染中文, 将重新编译之后的可执行文件替换之前的.