字重结构+family→字重子菜单(agent-111: fonts/<family>/<weight>/, gen_font.py --weight, 两级扫描, s_font_dropdown子菜单) + 全屏左滑滑条修复(agent-112)

This commit is contained in:
MeowOS Dev committed 2026-08-30 13:42:41 +08:00
1 parent e8fa373a2f
commit b75ecce5de
16 files changed
+531 -164

No files matched your search

+14 -6
View File
@@ -281,8 +281,8 @@ 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, tier, glyph_count, sizes, bitdepth,
png_path, idx_path):
def write_font_json(out_dir, name, family, weight, tier, glyph_count, sizes, bitdepth,
png_path, idx_path, source="", license_=""):
def sha256(path):
h = hashlib.sha256()
with open(path, "rb") as f:
@@ -292,6 +292,7 @@ def write_font_json(out_dir, name, family, tier, glyph_count, sizes, bitdepth,
meta = {
"family": family or name, # 同目录名(信息用;扫描端以目录名为 family)
"name": name, # 下拉显示名(缺则回退目录名)
"weight": weight or "regular", # 字重 slug(regular|bold|italic|…;默认 regular)
"glyph_count": glyph_count, # 信息用
"charset": tier, # common|gbk|full(档位;驱动按需加载)
"size_list": sizes, # 原生面字号
@@ -299,6 +300,8 @@ def write_font_json(out_dir, name, family, tier, glyph_count, sizes, bitdepth,
"sha256_png": sha256(png_path), # font.png 校验(扫描端仅 WARN)
"sha256_idx": sha256(idx_path), # font.idx 校验(扫描端仅 WARN)
}
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")
with open(jpath, "w", encoding="utf-8") as f:
json.dump(meta, f, ensure_ascii=False, indent=2)
@@ -315,10 +318,14 @@ def main():
ap.add_argument("--out", required=True)
ap.add_argument("--name", default="font")
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)")
ap.add_argument("--charset", default="common", choices=CHARSET_TIERS,
help="字体档位:common≈4k / gbk≈20k+ / full(可选,默认不推)")
ap.add_argument("--bitdepth", type=int, default=4, choices=(4, 8))
ap.add_argument("--extra", default="")
ap.add_argument("--source", default="", help="可选:font.json source 来源说明")
ap.add_argument("--license", default="", help="可选:font.json license 许可")
args = ap.parse_args()
os.makedirs(args.out, exist_ok=True)
@@ -393,15 +400,16 @@ def main():
idx_path = os.path.join(args.out, f"{args.name}.idx")
idx_size = write_idx(idx_path, args.bitdepth, face_meta, [p[3] for p in all_planes])
# ---- font.json(写入 charset + glyph_count + sha256,供扫描端标注档位/大小标记) ----
jpath = write_font_json(args.out, args.name, args.family, tier, charset_glyph_count(cps),
sizes, args.bitdepth, png_path, idx_path)
# ---- font.json(写入 weight + charset + glyph_count + sha256,供扫描端标注档位/大小标记) ----
jpath = write_font_json(args.out, args.name, args.family, args.weight, tier, charset_glyph_count(cps),
sizes, args.bitdepth, png_path, idx_path,
args.source, args.license)
png_size = os.path.getsize(png_path)
total = png_size + idx_size
print(f"\nfont.png {png_size} B")
print(f"font.idx {idx_size} B")
print(f"font.json {os.path.getsize(jpath)} B (charset={tier}, glyph_count={len(cps)})")
print(f"font.json {os.path.getsize(jpath)} B (charset={tier}, weight={args.weight or 'regular'}, glyph_count={len(cps)})")
print(f"合计 {total} B = {total/1024:.1f} KiB = {total/1048576:.2f} MiB (预算 2MiB)")