xiaozi 2024-08-09 10:36:26

从 ttc 中提取 ttf 字体文件 ttc2ttf.py

#!/usr/bin/env python3
import fontforge
import sys

# Usage: fontforge -script ttc2ttf.py /path/to/font.ttc
if len(sys.argv) != 2:
    print("Usage: fontforge -script ttc2ttf.py /path/to/font.ttc")
    sys.exit(1)

font_file = sys.argv[1]
fonts = fontforge.fontsInFile(font_file)
n = len(fonts)

for i in range(n):
    font = fontforge.open(f"{font_file}({fonts[i]})")

    index = str(i + 1).zfill(2)  # Pad with zero if less than 10
    ext = ".ttf"  # Always generate TTF files

    filename = f"{font.fontname}-{index}{ext}"
    font.generate(filename)
    print(filename)
    font.close()

评论

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.1. UTC+08:00, 2024-11-17 19:25
浙ICP备14020137号-1 $访客地图$