我的最终目标是创建从glyph_id
到unicode_chars
的映射。这种映射在某种程度上是有序的glyph_id --> uni_1, uni_2, uni_3 ...
,因为单个glyph可以映射到许多有序的unicode_characters
我正在寻找一些工具或库,最好是在python中,通过它我可以访问所有的元信息,如表格内的字体
另外,我正在寻找一些可靠的源代码,通过这些源代码我可以理解将多个Unicode映射到glyph的过程
我知道harfbuzz之类的工具会在给定的Unicode字符串上生成(glyph,position)对。但我不确定它是否会反过来
谢谢你的帮助
您可能应该查看fontToolsPython库,其中包含处理字体所需的组件
您感兴趣的字体表是“cmap”表,您需要的基本上是Unicode映射子表的反向映射(有几种子表可以映射Unicodes;如果您不熟悉这个概念,我建议您查看OpenType specification以获取更多信息)。基本上,你得到了Unicode到glyph的映射,然后反过来
fontTools实际上有一个很好的特性,可以自动选择“最佳”cmap子表(它有一个首选cmap子表类型的有序列表,并返回您打开的特定字体中的第一个可用字体)。下面是使用该函数的示例:
reverse_unicode_map
现在保存glyph(glyph name)到整数代码点列表的映射:您可以看到有两个glyph,“.null”和“nonmarkingreturn”映射到多个Unicode
如果需要将glyph名称解析为glyph索引,可以使用
font.getGlyphID()
方法(传入glyph名称;它将返回相应的整数ID)相关问题 更多 >
编程相关推荐