游戏的中文字体文件

游戏引擎一般用FreeType库读取字体文件。
为显示中文,引擎一般会要求游戏自带中文字体(系统字体的情况太复杂,有字体选择困难症)。

字体选择

黑体在屏幕上显示效果比较好,可以使用思源黑体思源宋体也不错。
它们都采用SIL Open Font License

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works.

思源黑体的Region Specific Subset OTFs Simplified Chinese (简体中文)字体文件较小。
黑体的字重(Weight,权)用Normal或Regular即可。
宋体的话用Normal或SemiBold比较好看。

字体子集化精简

如果游戏没有聊天功能,用到的字比较少,可以考虑精简字体。可以用 Python 的 fonttools 包含的 pyftsubset 子集化功能来实现。
安装:

py -m pip install --upgrade fonttools

在命令提示符窗口执行:

pyftsubset SourceHanSansCN-Normal.otf --text-file=charlist.txt --output-file=zh_CN.otf

其中 charlist.txt 文件采用UTF-8编码,包含了所有可能会显示的字符(包括非中文字符)。
精简后的效果:
在这里插入图片描述
字数极大地减少了。
如果需要将字体文件转换成其它非OTF字体格式,如TTF,可以用 FontForge 处理(先CID->Flatten, 再File->Generate Fonts…)。

参考

GB/T 16964.1-1997 字型信息交换 第1部分 体系结构
GB 18030 中文编码字符集
GitHub:思源黑体
知乎:Font­Tools 字体子集化
知乎:字体的字重是什么
FontForge:Menus

猜你喜欢

转载自blog.csdn.net/feiyunw/article/details/127409982
今日推荐