Lanly109 / headimg_generator

基于HoshinoBot的制作头像相关的表情包插件,移植自nonebot-plugin-petpet
MIT License
50 stars 11 forks source link

新版本前后端分离后,关于中文显示方块/无法加载字体的一种解决思路 #38

Closed SlightDust closed 1 year ago

SlightDust commented 1 year ago

系统是Debian 11
尝试了把字体放在resources/fonts/usr/share/fonts/meme,然后fc-cache -fv均无效。
具体表现为表情包制作内显示方块,表情帮助 字符画后台提示findfont: Font family ['Consolas'] not found. Falling back to DejaVu Sans.
8ef457dee3e5ab7997ca813d5b61c07 7f67b37cff0b6706776ab65f5941736

最后参考了 http://bcxw.net/article/849.html
进入python命令行,执行
import matplotlib print(matplotlib.matplotlib_fname()) 应该会得到一个类似/usr/local/lib/python3.9/dist-packages/matplotlib/mpl-data/matplotlibrc的路径,注意python版本号的区别
然后进入这个路径下的mpl-data/fonts/路径,把其他用到的字体一股脑丢进来。 root@debian:/usr/local/lib/python3.9/dist-packages/matplotlib/mpl-data/fonts/ttf# cp /usr/share/fonts/meme/* .
image

再次进入python命令行,执行
import matplotlib print(matplotlib.get_cachedir()) 应该会得到一个类似/root/.cache/matplotlib的路径
把这个路径下的内容删干净rm -rf /root/.cache/matplotlib/*

然后重启Hoshino,应该就可以了

猜测是meme_generator用了mpl但是没有设置字体路径导致的。python小白,没翻meme_generator源码。
也不排除是系统或者python版本的原因。

附:系统信息

root@debian:/usr# uname -a Linux debian 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux root@debian:/usr# cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

Lanly109 commented 1 year ago

感谢建议,我也见到了源仓库里新增了说明,我同步一下

kcn3388 commented 1 year ago

@Lanly109 @SlightDust 并不需要这么麻烦。 在安装字体之前就安装了matplotlib的话需要删除matplotlib的缓存,这是matplotlib那边的问题,清除缓存以后即可正确读取到字体。 用jupyter搞炼丹的应该对这个问题很熟悉

另外,不建议对Python package进行修改,可能会出现潜在的问题。 对于Linux系统,缓存目录应该是:

~/.cache/matplotlib/*.json

对于Windows系统,缓存目录应为:

C:\Users\<Your User Name>\.matplotlib\*.json
SlightDust commented 1 year ago

@Lanly109 @SlightDust 并不需要这么麻烦。 在安装字体之前就安装了matplotlib的话需要删除matplotlib的缓存,这是matplotlib那边的问题,清除缓存以后即可正确读取到字体。 ~用jupyter搞炼丹的应该对这个问题很熟悉~

另外,不建议对Python package进行修改,可能会出现潜在的问题。 对于Linux系统,缓存目录应该是:

~/.cache/matplotlib/*.json

对于Windows系统,缓存目录应为:

C:\Users\<Your User Name>\.matplotlib\*.json

原来如此。学到了,感谢!