【问题标题】:How do I convert a woff2 font to ttf using fonttools in Python?如何在 Python 中使用 fonttools 将 woff2 字体转换为 ttf?
【发布时间】:2020-10-20 11:43:38
【问题描述】:

我有想要使用 Python 和 fonttools 库转换为 ttf 的 woff2 文件。我已经看到了一些关于如何将 ttf 字体转换为 woff2 的方法,但我不能用它们来做相反的事情。

提前致谢

【问题讨论】:

    标签: python fonts truetype woff2


    【解决方案1】:
    from fontTools.ttLib import woff2
    # you also need brotli
    import os
    
    def convert(infilename, outfilename):
        with open(infilename , mode='rb') as infile:
            with open(outfilename, mode='wb') as outfile:
                woff2.decompress(infile, outfile)
    

    这是我编写的 CLI 友好脚本 https://github.com/basisvectors/woff2otf

    python woff2otf.py (filename.woff or filename.woff2 or directory for batch conversion) [target file or dir name]
    

    【讨论】:

      【解决方案2】:

      我发现可以使用fontTools.ttLib.woff2.decompress() 来实现这一目标

      【讨论】:

      • 我很想知道:如何才能弄清楚这一点?您是否在 FT 文档中找到了正确的详细信息?拼凑来自 stackoverflow 或其他地方的帖子的见解?深入了解 FT 代码?
      • 我搜索了有关“brotli”(woff2 所需的 fonttools 依赖项)的信息,并遇到了this Github repo,它声明它是一种压缩格式,所以我然后试图看看如果我解压缩 woff2 会发生什么使用fontTools.ttLib.woff2.decompress()的字体,我看到它解压缩为ttf
      猜你喜欢
      • 2020-05-19
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      • 2019-07-29
      • 2013-03-05
      • 2014-11-09
      相关资源
      最近更新 更多