mirror of
https://github.com/YuleBest/FontMM.git
synced 2026-12-04 03:11:48 +08:00
英文字体自带中文字形时, apply.sh 会先裁成纯拉丁子集再安装 (issue #10), 但 WebUI 上仍显示原字体大小、也没有任何标记, 看起来像裁切没生效。 - 新增英文子集大小读取: 读 FONTS/.en-subset.ttf, 且要求它比 en.ttf 新 (换过英文字体但还没重新应用时, 旧子集不该继续展示) - 英文槽位卡片改为「原大小 → 子集大小」并加「已子集化」徽标; 子集常在 百 KB 量级, 小于 1MB 时改用 KB, 否则会显示成 0.2 MB 看不出量级 - 应用完成后自动刷新该状态; 重新选择英文字体时先撤下徽标 (它描述的是 上次应用的结果, 不是当前选择的) - apply.sh 未使用子集时清掉残留的子集文件, 使该文件的存在即代表本次应用 确实用了子集
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { exec, shellQuote, toast } from './ksu';
|
|
import { copyFont, pickWghtRange, refreshEnSubset, renderSlots, setApplying, slots } from './slots';
|
|
import { applyWghtOverride, getSelectedWghtMode, writeWghtMode } from './wght';
|
|
import { invalidateTestFonts } from './testFonts';
|
|
import { applyBtn } from './dom';
|
|
import { FONTS_DIR } from './constants';
|
|
|
|
const logDialog = document.getElementById('log-dialog') as any;
|
|
const logContent = document.getElementById('log-content')!;
|
|
|
|
document.getElementById('log-close')?.addEventListener('click', () => {
|
|
logDialog.open = false;
|
|
});
|
|
|
|
async function apply() {
|
|
if (!slots.hans.path) return;
|
|
setApplying(true);
|
|
renderSlots();
|
|
try {
|
|
// 字重范围覆写: 用 UI 当前模式 (持久化到 FONTS/wght-mode.txt), 仅当存在可变字体且模式非 0 时处理
|
|
const wghtMode = getSelectedWghtMode();
|
|
await writeWghtMode(wghtMode);
|
|
const wghtPick = pickWghtRange();
|
|
if (wghtMode !== 0 && wghtPick) {
|
|
// Go 程序自行读取 wght-map.txt (mode 3)
|
|
await applyWghtOverride(wghtMode, wghtPick.min, wghtPick.max);
|
|
}
|
|
|
|
// 启动加载的字体 path 即 FONT/ 内的文件, 无需再复制
|
|
if (slots.hans.path !== `${FONTS_DIR}/hans.ttf`) {
|
|
await copyFont(slots.hans.path, `${FONTS_DIR}/hans.ttf`);
|
|
}
|
|
|
|
if (slots.hant.path) {
|
|
if (slots.hant.path !== `${FONTS_DIR}/hant.ttf`) {
|
|
await copyFont(slots.hant.path, `${FONTS_DIR}/hant.ttf`);
|
|
}
|
|
} else {
|
|
await exec(`rm -f ${shellQuote(`${FONTS_DIR}/hant.ttf`)}`);
|
|
}
|
|
|
|
if (slots.en.path) {
|
|
if (slots.en.path !== `${FONTS_DIR}/en.ttf`) {
|
|
await copyFont(slots.en.path, `${FONTS_DIR}/en.ttf`);
|
|
}
|
|
} else {
|
|
await exec(`rm -f ${shellQuote(`${FONTS_DIR}/en.ttf`)}`);
|
|
}
|
|
|
|
if (slots.mono.path) {
|
|
if (slots.mono.path !== `${FONTS_DIR}/mono.ttf`) {
|
|
await copyFont(slots.mono.path, `${FONTS_DIR}/mono.ttf`);
|
|
}
|
|
} else {
|
|
await exec(`rm -f ${shellQuote(`${FONTS_DIR}/mono.ttf`)}`);
|
|
}
|
|
|
|
if (slots.emoji.path) {
|
|
if (slots.emoji.path !== `${FONTS_DIR}/emoji.ttf`) {
|
|
await copyFont(slots.emoji.path, `${FONTS_DIR}/emoji.ttf`);
|
|
}
|
|
} else {
|
|
await exec(`rm -f ${shellQuote(`${FONTS_DIR}/emoji.ttf`)}`);
|
|
}
|
|
|
|
const { errno, stdout, stderr } = await exec('sh /data/adb/modules/FontMM/apply.sh');
|
|
if (errno !== 0) throw new Error(stderr || 'apply.sh 执行失败');
|
|
|
|
if (logContent && logDialog) {
|
|
logContent.textContent = stdout;
|
|
logDialog.open = true;
|
|
}
|
|
toast('字体已应用,重启后生效');
|
|
// 字体已变化: 下次进入测试页时重新加载
|
|
invalidateTestFonts();
|
|
} catch (e) {
|
|
toast(`应用失败: ${String(e)}`);
|
|
} finally {
|
|
setApplying(false);
|
|
// 应用后刷新英文子集结果 (issue #14): 子集大小只有跑过 apply.sh 才知道
|
|
await refreshEnSubset();
|
|
renderSlots();
|
|
}
|
|
}
|
|
|
|
applyBtn?.addEventListener('click', apply);
|