通过一个例子,了解一下fontTools库的简单使用
# coding:utf-8 from fontTools.ttLib import TTFont tf = TTFont(\'ztk01.woff\') #实例化字体对象,也可以从内存中读取数据 tf = TTFont(BytesIO(data)) tf.saveXML(\'ztk01.xml\') #存储为xml格式文件 uninames = tf.getGlyphNames()[1:-1] #获取所有字符的unicode编码 print(uninames) #[\'uniE06A\', \'uniE0C0\', \'uniE0D2\', \'uniE0DB\', \'uniE0E1\', \'uniE1A4\', \'uniE1E0\', ...,\'uniF62A\', \'uniF66C\'] cos = tf[\'glyf\'][uninames[1]].coordinates #获取某个字符的坐标 print(cos) #GlyphCoordinates([(543, 826),(918, 850),(1124, 844),(666, 841),(1110, 826),...,(672, 411)])