pip install fontTools
from fontTools.ttLib import TTFont
# 加载字体文件:
font = TTFont('maoyan.woff')
# 转为xml文件:
font.saveXML('maoyan.xml')
from fontTools.ttLib import TTFont
# 加载字体文件:
font = TTFont('XRXV3I6Li01BKofINeaB.woff2')
kv = font.keys()
print(kv)
运行结果:
['GlyphOrder', 'head', 'hhea', 'maxp', 'OS/2', 'hmtx', 'cmap', 'fpgm', 'prep', 'cvt ', 'loca', 'glyf', 'name', 'post', 'gasp', 'GDEF', 'GPOS', 'GSUB']
font.getGlyphOrder()
运行结果:
['.notdef', 'cid00001', 'cid00017', 'cid00018', 'cid00019', 'cid00020', 'cid00021', 'cid00022', 'cid00023', 'cid00024', 'cid00025', 'cid00026']
print(font.getGlyphOrder())
运行结果:
{48: 'cid00026', 49: 'cid00017', 50: 'cid00019', 51: 'cid00024', 52: 'cid00022', 53: 'cid00021', 54: 'cid00020', 55: 'cid00018', 56: 'cid00025', 57: 'cid00023'}
#font['glyf'][字体编码].coordinates
font['glyf']['one'].coordinates
运行结果:
GlyphCoordinates([(510, 69),(530, 51),(530, 35),(530, 18),(511, 0),(492, 0),(161, 0),(142, 0),(123, 18),(123, 35),(123, 51),(143, 69),(161, 69),(285, 69),(285, 605),(176, 534),(168, 529),(160, 529),(146, 529),(125, 555),(125, 570),(125, 591),(141, 600),(293, 699),(310, 710),(328, 710),(345, 710),(367, 688),(367, 668),(367, 69),(492, 69)])
#font['glyf'][字体'].flags
font['glyf']['one'].flags
运行结果:
array('B', [0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1])
1、一个最基本的字体文件一定会包含以下的表:
cmap: Character to glyph mapping unicode跟 Name的映射关系
head: Font header 字体全局信息
hhea: Horizontal header 定义了水平header
hmtx: Horizontal metrics 定义了水平metric
maxp: Maximum profile 用于为字体分配内存
name: Naming table 定义字体名称、风格名以及版权说明等
glyf: 字形数据即轮廓定义和调整指令
OS__2: OS__2 and Windows specific metrics
post: PostScript information
2、高级书法特性的字体包含表:
BASE: Baseline data
GDEF: Glyph definition data
GPOS: Glyph positioning data
GSUB: Glyph substitution data
JSTF: Justification data
MATH: Math layout data