UI 菜单初步完成
This commit is contained in:
@@ -85,8 +85,10 @@ def main():
|
||||
chars |= collect(open(f, encoding='utf-8-sig', errors='ignore').read())
|
||||
s = ''.join(sorted(chars))
|
||||
out_path = os.path.join(ROOT, 'ui_cn_chars.txt')
|
||||
with open(out_path, 'w', encoding='utf-8') as fp:
|
||||
fp.write(s)
|
||||
# newline='' 关闭行尾转换:恒输出 LF(与 gen_menu.py / make_font.py 一致),
|
||||
# 避免同一脚本在 Windows 出 CRLF、Linux 出 LF 导致提交产物跨平台 diff
|
||||
with open(out_path, 'w', encoding='utf-8', newline='') as fp:
|
||||
fp.write(s + '\n')
|
||||
print('scanned %d files; unique non-ASCII chars: %d' % (len(SCAN), len(s)))
|
||||
print('->', out_path)
|
||||
|
||||
|
||||
@@ -110,7 +110,30 @@ def merge_arrow_glyph(font_path):
|
||||
print('已合并箭头 U+25B6:位图+%d 字节,glyph_id=%d' % (len(ARROW_BITMAP), glyph_count))
|
||||
|
||||
|
||||
def fix_trailing_newline(path):
|
||||
"""规范化文件末尾为恰好一个 \n(pre-commit end-of-file-fixer 要求)。
|
||||
|
||||
lv_font_conv 产物末尾多一个空行(`#endif` 之后 `\n\n`),统一在此收敛为单个换行,
|
||||
避免每次重生成字体都触发 end-of-file-fixer 拦截提交。
|
||||
"""
|
||||
with open(path, 'rb') as fp:
|
||||
data = fp.read()
|
||||
body = data
|
||||
while body.endswith(b'\r\n') or body.endswith(b'\n'):
|
||||
body = body[:-2] if body.endswith(b'\r\n') else body[:-1]
|
||||
fixed = body + b'\n'
|
||||
if fixed != data:
|
||||
with open(path, 'wb') as fp:
|
||||
fp.write(fixed)
|
||||
|
||||
|
||||
def main():
|
||||
# Windows GBK 控制台无法打印 ▶ 等符号:降级为替换字符,避免 UnicodeEncodeError 崩溃
|
||||
try:
|
||||
sys.stdout.reconfigure(errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('--bpp', type=int, default=1, help='字体位深 1/2/3(默认 1)')
|
||||
ap.add_argument('--size', type=int, default=12, help='字号(默认 12)')
|
||||
@@ -138,6 +161,7 @@ def main():
|
||||
if r.returncode != 0:
|
||||
sys.exit('FAILED rc=%d' % r.returncode)
|
||||
merge_arrow_glyph(OUT) # 补回宋体缺失的 ▶ 字形(幂等)
|
||||
fix_trailing_newline(OUT) # 规范化末尾换行(pre-commit end-of-file-fixer)
|
||||
print('OK %d bytes -> %s' % (os.path.getsize(OUT), OUT))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user