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

The Chinese in the picture is garbled #93

Open
yihanglee-cn opened this issue May 13, 2024 · 9 comments
Open

The Chinese in the picture is garbled #93

yihanglee-cn opened this issue May 13, 2024 · 9 comments

Comments

@yihanglee-cn
Copy link

yihanglee-cn commented May 13, 2024

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

  • OS: Windows 11
  • Version: Latest
@AlejandroSuero
Copy link
Contributor

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
Copy link

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

@yihanglee-cn
Copy link
Author

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

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

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
Copy link
Contributor

@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
Copy link
Author

@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
Copy link

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

@wangdaming261
Copy link

wangdaming261 commented May 17, 2024

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

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

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
Copy link
Author

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

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

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
Copy link

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

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

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)
}

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

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

4 participants