diff --git a/功能/TTC文件拆分.sh b/功能/TTC文件拆分.sh new file mode 100644 index 0000000..0f3b6a4 --- /dev/null +++ b/功能/TTC文件拆分.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# FontMM +# TTC 文件拆分 +# By Yule +# shellcheck disable=SC2154 + +# 配置 +SCRIPT_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")" +WORK_DIR="$SCRIPT_DIR/WORK" +export PATH="$PATH:$SCRIPT_DIR/功能/bin" +clear + +# 环境检查 +if ! command -v yq >/dev/null 2>&1; then + echo -e "${re}[错误] 缺少 yq,请安装后重试${res}" + exit 1 +fi + +mkdir -p "$WORK_DIR/ttc_separated" + +echo -en "- 输入一个 TTC 文件完整路径:" +read -r ttc_file + +if [ ! -f "$ttc_file" ]; then + echo "! $ttc_file 文件不存在" + exit 1 +fi + +if ! file "$ttc_file" | grep -q "TrueType font collection"; then + echo "! 这不是一个 TTC 文件" + exit 2 +fi + +if ttc_splitter "$ttc_file" -o "$WORK_DIR/ttc_separated"; then + echo "~ 拆分成功" + exit 0 +else + echo "! 有文件拆分失败" + exit 3 +fi diff --git a/功能/bin/ttc_splitter b/功能/bin/ttc_splitter new file mode 100755 index 0000000..a392ebe Binary files /dev/null and b/功能/bin/ttc_splitter differ diff --git a/功能/bin/ttc_splitter.py b/功能/bin/ttc_splitter.py new file mode 100644 index 0000000..607878d --- /dev/null +++ b/功能/bin/ttc_splitter.py @@ -0,0 +1,68 @@ +import os +import sys +import argparse +from fontTools.ttLib import TTCollection + +def get_font_name(font): + """从字体元数据中提取可读名称""" + name = "" + # 优先寻找英文全名 (nameID 4, platformID 3) + for record in font['name'].names: + if record.nameID == 4: + try: + name = record.toUnicode().replace(" ", "_") + if record.platformID == 3: # Windows 平台 ID 比较稳 + break + except: + continue + return name if name else "unknown_font" + +def main(): + parser = argparse.ArgumentParser(description="TTC 字体提取工具 - 由于乐 Yule 维护") + parser.add_argument("input", help="输入的 .ttc 文件路径") + parser.add_argument("-o", "--output", help="输出目录 (默认为当前目录下的 extracted_fonts)") + + args = parser.parse_args() + + input_file = args.input + output_base = args.output if args.output else os.path.join(os.getcwd(), "extracted_fonts") + + if not os.path.isfile(input_file): + print(f"[-] 错误: 找不到输入文件 '{input_file}'") + return + + if not os.path.exists(output_base): + os.makedirs(output_base) + print(f"[*] 已创建输出目录: {output_base}") + + print("="*50) + print(f"[*] 正在读取集合: {os.path.basename(input_file)}") + + try: + collection = TTCollection(input_file) + total = len(collection) + print(f"[*] 发现子字体总数: {total}") + print("="*50) + + for i, font in enumerate(collection): + font_name = get_font_name(font) + file_name = f"{font_name}.ttf" + output_path = os.path.join(output_base, file_name) + + # 处理重名问题 + counter = 1 + while os.path.exists(output_path): + output_path = os.path.join(output_base, f"{font_name}_{counter}.ttf") + counter += 1 + + print(f"[{i+1}/{total}] 正在导出: {os.path.basename(output_path)} ...", end="\r") + font.save(output_path) + + print(f"\n" + "="*50) + print(f"[+] 提取完成!所有文件保存在: {output_base}") + + except Exception as e: + print(f"\n[-] 发生致命错误: {e}") + +if __name__ == "__main__": + main() diff --git a/功能/bin/ttc_splitter.sha256 b/功能/bin/ttc_splitter.sha256 new file mode 100644 index 0000000..9c5922b --- /dev/null +++ b/功能/bin/ttc_splitter.sha256 @@ -0,0 +1 @@ +943df550b1fe5725230ca6ceae92fee3dde549a6c7b9080508bf6d945089b762 \ No newline at end of file