woff转xml
首先我们可以利用 fontTools 库把他保存为xml文件进行查看
#encoding: utf-8
from fontTools.ttLib import TTFont
font = TTFont(r'C:\Users\Administrator\Desktop\adderss.woff')
font.saveXML(r'C:\Users\Administrator\Desktop\adderss.xml')
xml文件解析
接下来我们打开xml文件 可以看到他里面主要包含有 GlyphOrder 字形排序、cmap 存储 unicode跟 Name的映射关系、glyf 绘画字形的信息。
例如:
举例
在img1中我们可以看到 GlyphOrder排序id为3的对应unie761 然后img2中cmap 的unie761与0xe761 对应 在img3 中可以看到 name为unie761他下面存在轮廓线条。接下来我们就把那个contour用matplotlib描绘一下。
matplotlib描绘图片
这里用matplotlib对glyf的坐标进行描绘
#encoding: utf-8
import matplotlib.pyplot as plt
import re
str = """
<contour>
<pt x="310" y="728" on="1"/>
<pt x="202" y="728" on="0"/>
<pt x="69" y="585" on="0"/>
<pt x="68" y="465" on="1"/>
<pt x="150" y="465" on="1"/>
<pt x="152" y="560" on="0"/>
<pt x="194" y="608" on="1"/>
<pt x="233" y="659" on="0"/>
<pt x="307" y="658" on="1"/>
<pt x="377" y="658" on="0"/>
<pt x="455" y="587" on="0"/>
<pt x="455" y="521" on="1"/>
<pt x="455" y="452" on="0"/>
<pt x="400" y="393" on="1"/>
<pt x="372" y="364" on="0"/>
<pt x="288" y="304" on="1"/>
<pt x="175" y="226" on="0"/>
<pt x="133" y="177" on="1"/>
<pt x="62" y="98" on="0"/>
<pt x="62" y="0" on="1"/>
<pt x="538" y="0" on="1"/>
<pt x="538" y="73" on="1"/>
<pt x="163" y="73" on="1"/>
<pt x="183" y="145" on="0"/>
<pt x="319" y="237" on="1"/>
<pt x="430" y="313" on="0"/>
<pt x="467" y="352" on="1"/>
<pt x="537" y="427" on="0"/>
<pt x="537" y="614" on="0"/>
<pt x="409" y="728" on="0"/>
</contour>
"""
x = [int(i) for i in re.findall(r'<pt x="(.*?)" y=', str)]
y = [int(i) for i in re.findall(r'y="(.*?)" on=', str)]
plt.plot(x, y)
plt.show()
结果图片
从结果图中可以看到2,他就是所要表达的数字