feat(font): gen_font.py 支持 tier/languages/label/--json-name (agent-188, 思源黑体7字重10套已产出入卡) + APPS.md §3.7 音频通路实测定案(MeowOS常驻模式声卡空闲App直开hw:0,0) + §3.8 版本号规则(version_code 安卓式)
This commit is contained in:
1 parent
cf86cbd387
commit
f7e45f472e
2 files changed
+32
-6
No files matched your search
+16
-5
@@ -282,7 +282,7 @@ def write_idx(path, bit_depth, faces, glyph_tabs):
|
||||
# font.json(元数据 + 完整性校验;schema 见 docs/MEOWOS_SPEC_REF.md §5.2)
|
||||
# --------------------------------------------------------------------------
|
||||
def write_font_json(out_dir, name, family, weight, tier, glyph_count, sizes, bitdepth,
|
||||
png_path, idx_path, source="", license_=""):
|
||||
png_path, idx_path, source="", license_="", languages=None, label=""):
|
||||
def sha256(path):
|
||||
h = hashlib.sha256()
|
||||
with open(path, "rb") as f:
|
||||
@@ -294,12 +294,15 @@ def write_font_json(out_dir, name, family, weight, tier, glyph_count, sizes, bit
|
||||
"name": name, # 下拉显示名(缺则回退目录名)
|
||||
"weight": weight or "regular", # 字重 slug(regular|bold|italic|…;默认 regular)
|
||||
"glyph_count": glyph_count, # 信息用
|
||||
"charset": tier, # common|gbk|full(档位;驱动按需加载)
|
||||
"charset": tier, # common|gbk|full(档位;驱动按需加载——现行运行时读此作 tier)
|
||||
"tier": tier, # 档位(FONT_SYSTEM 新增;同 charset 值,供后续运行时迁移)
|
||||
"languages": languages or ["zh_cn", "en_us"], # 详细区域码(FONT_SYSTEM §2.1)
|
||||
"size_list": sizes, # 原生面字号
|
||||
"bit_depth": bitdepth, # 4|8
|
||||
"sha256_png": sha256(png_path), # font.png 校验(扫描端仅 WARN)
|
||||
"sha256_idx": sha256(idx_path), # font.idx 校验(扫描端仅 WARN)
|
||||
}
|
||||
if label: meta["label"] = label # 可选:显示名(如 `思源黑体 CN·粗体·常用`)
|
||||
if source: meta["source"] = source # 可选:来源(如 "MiSans Regular (Xiaomi)")
|
||||
if license_: meta["license"] = license_ # 可选:许可(如 "SIL Open Font License 1.1")
|
||||
jpath = os.path.join(out_dir, "font.json")
|
||||
@@ -316,7 +319,10 @@ def main():
|
||||
ap.add_argument("--font", required=True)
|
||||
ap.add_argument("--sizes", default="28,20")
|
||||
ap.add_argument("--out", required=True)
|
||||
ap.add_argument("--name", default="font")
|
||||
ap.add_argument("--name", default="font",
|
||||
help="输出面基名(font.png/font.idx 基名,缺省 font;font.json name 缺省同此)")
|
||||
ap.add_argument("--json-name", default="",
|
||||
help="font.json name 显示名(缺省 = --name;用于 png 基名与显示名解耦)")
|
||||
ap.add_argument("--family", default="", help="font.json family(缺省 = --name;信息用)")
|
||||
ap.add_argument("--weight", default="regular",
|
||||
help="字重 slug(regular|bold|italic|…,缺省 regular;写进 font.json weight)")
|
||||
@@ -326,11 +332,15 @@ def main():
|
||||
ap.add_argument("--extra", default="")
|
||||
ap.add_argument("--source", default="", help="可选:font.json source 来源说明")
|
||||
ap.add_argument("--license", default="", help="可选:font.json license 许可")
|
||||
ap.add_argument("--languages", default="zh_cn,en_us",
|
||||
help="font.json languages 区域码(逗号分隔,FONT_SYSTEM §2.1;默认 zh_cn,en_us)")
|
||||
ap.add_argument("--label", default="", help="可选:font.json label 显示名")
|
||||
args = ap.parse_args()
|
||||
|
||||
os.makedirs(args.out, exist_ok=True)
|
||||
sizes = [int(s) for s in args.sizes.split(",") if s.strip()]
|
||||
tier = CHARSET_ALIAS.get(args.charset, "common")
|
||||
json_name = args.json_name if args.json_name else args.name
|
||||
cps = build_charset(tier, args.extra)
|
||||
print(f"字符集: {len(cps)} 码位 (charset={tier})")
|
||||
|
||||
@@ -401,9 +411,10 @@ def main():
|
||||
idx_size = write_idx(idx_path, args.bitdepth, face_meta, [p[3] for p in all_planes])
|
||||
|
||||
# ---- font.json(写入 weight + charset + glyph_count + sha256,供扫描端标注档位/大小标记) ----
|
||||
jpath = write_font_json(args.out, args.name, args.family, args.weight, tier, charset_glyph_count(cps),
|
||||
languages = [l.strip() for l in args.languages.split(",") if l.strip()]
|
||||
jpath = write_font_json(args.out, json_name, args.family, args.weight, tier, charset_glyph_count(cps),
|
||||
sizes, args.bitdepth, png_path, idx_path,
|
||||
args.source, args.license)
|
||||
args.source, args.license, languages, args.label)
|
||||
|
||||
png_size = os.path.getsize(png_path)
|
||||
total = png_size + idx_size
|
||||
|
||||
Reference in new issue
Block a user