woff字体文件转xml介绍

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,他就是所要表达的数字

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值