mirror of
https://github.com/YuleBest/FontMM.git
synced 2026-12-04 03:11:48 +08:00
revert(metrics): 移除固定行距字距功能, 不再改动字体本身 (issue #17)
实测只要在 WebUI 改动「固定行距 & 字距」就会触发开机失败, 把设置恢复默认同样触发, 不动该设置则一切正常; beta.9 已因此撤回。为保险起见整套功能删除: - apply.sh: 删掉 unify_one / MANAGED_FONTS 与 metrics.txt、line-height.txt 读取 - fontmm-subset: 删掉 -line-metrics 模式 (sfnt/字体集合解析与 hhea/OS-2/head 改写) - WebUI: 删掉高级配置里的开关与档位, 以及 dev 模式的伪 exec 分支 - customize.sh: 设置继承清单去掉 metrics.txt / line-height.txt - README / DEVELOPMENT / dev/ci.mjs 同步移除相关章节与检查
This commit is contained in:
1 parent
03a565ddea
commit
e5288439dd
12 files changed
+12
-666
No files matched your search
@@ -145,31 +145,6 @@
|
||||
</md-outlined-select>
|
||||
</div>
|
||||
|
||||
<!-- 固定行距/字距 (issue #17) -->
|
||||
<div class="wght-mode-row">
|
||||
<div class="wght-mode-info">
|
||||
<div class="wght-mode-title">固定行距 & 字距</div>
|
||||
<div class="wght-mode-sub" id="metrics-sub">
|
||||
把装入字体的行距统一到下面档位、并收掉虚高的上下留白;换字体后行距不再跟着变。开启后需重新「应用」。
|
||||
</div>
|
||||
</div>
|
||||
<md-switch id="metrics-switch" aria-label="固定行距字距"></md-switch>
|
||||
</div>
|
||||
<div class="wght-mode-row">
|
||||
<div class="wght-mode-info">
|
||||
<div class="wght-mode-title">行距档位</div>
|
||||
<div class="wght-mode-sub" id="metrics-level-sub">
|
||||
按字身框倍数统一行距:紧凑 1.20 / 标准 1.45 / 宽松
|
||||
1.60;字体上下的比例保持不变。
|
||||
</div>
|
||||
</div>
|
||||
<md-outlined-select id="metrics-level-select" label="行距档位">
|
||||
<md-select-option value="1200">紧凑</md-select-option>
|
||||
<md-select-option value="1450" selected>标准</md-select-option>
|
||||
<md-select-option value="1600">宽松</md-select-option>
|
||||
</md-outlined-select>
|
||||
</div>
|
||||
|
||||
<!-- 字重映射 (各模式实时预览, 修改即切为自定义) -->
|
||||
<div class="wght-map" id="wght-map">
|
||||
<div class="wght-map-inner">
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { exec, shellQuote, toast } from './ksu';
|
||||
import { copyFont, pickWghtRange, refreshEnSubset, renderSlots, setApplying, slots } from './slots';
|
||||
import { applyWghtOverride, getSelectedWghtMode, writeWghtMode } from './wght';
|
||||
import { getSelectedLevel, getSelectedMetrics, writeLevel, writeMetrics } from './metrics';
|
||||
import { invalidateTestFonts } from './testFonts';
|
||||
import { applyBtn } from './dom';
|
||||
import { FONTS_DIR } from './constants';
|
||||
@@ -21,9 +20,6 @@ async function apply() {
|
||||
// 字重范围覆写: 用 UI 当前模式 (持久化到 FONTS/wght-mode.txt), 仅当存在可变字体且模式非 0 时处理
|
||||
const wghtMode = getSelectedWghtMode();
|
||||
await writeWghtMode(wghtMode);
|
||||
// 固定行距字距: 开关与档位同样先落盘 —— 载体插入与字体行距统一都在 apply.sh 里按它们进行
|
||||
await writeMetrics(getSelectedMetrics());
|
||||
await writeLevel(getSelectedLevel());
|
||||
const wghtPick = pickWghtRange();
|
||||
if (wghtMode !== 0 && wghtPick) {
|
||||
// Go 程序自行读取 wght-map.txt (mode 3)
|
||||
|
||||
@@ -39,10 +39,6 @@ const FAKE_FS: Record<string, { dirs: string[]; fonts: string[]; files: string[]
|
||||
'/storage/emulated/0/字体': { dirs: [], fonts: ['思源黑体.ttf', '霞鹜文楷.ttf'], files: [] },
|
||||
};
|
||||
|
||||
// dev 模式下的固定行距字距开关与档位 (FONTS/metrics.txt、FONTS/line-height.txt 的内存态)
|
||||
let mockMetrics = '0';
|
||||
let mockLineHeight = '1450';
|
||||
|
||||
async function mockExec(command: string): Promise<ExecResult> {
|
||||
const fake = (stdout = ''): ExecResult => ({ errno: 0, stdout, stderr: '' });
|
||||
const fail = (stderr: string): ExecResult => ({ errno: 1, stdout: '', stderr });
|
||||
@@ -79,23 +75,6 @@ async function mockExec(command: string): Promise<ExecResult> {
|
||||
if (command.includes('wght-mode.txt')) {
|
||||
return command.includes('echo') ? fake('') : slow('1');
|
||||
}
|
||||
// 固定行距字距开关/档位: 内存态往返 (echo 写, cat 读), 便于 dev 下验证持久化
|
||||
if (command.includes('metrics.txt')) {
|
||||
if (command.includes('echo')) {
|
||||
const m = command.match(/echo '(\d)'/);
|
||||
if (m) mockMetrics = m[1];
|
||||
return fake('');
|
||||
}
|
||||
return slow(mockMetrics);
|
||||
}
|
||||
if (command.includes('line-height.txt')) {
|
||||
if (command.includes('echo')) {
|
||||
const m = command.match(/echo '(\d+)'/);
|
||||
if (m) mockLineHeight = m[1];
|
||||
return fake('');
|
||||
}
|
||||
return slow(mockLineHeight);
|
||||
}
|
||||
// 字重覆写: Go 程序 fontmm-wght (模拟成功日志)
|
||||
if (command.includes('fontmm-wght')) {
|
||||
return slow(
|
||||
|
||||
@@ -2,7 +2,6 @@ import './material';
|
||||
// 各功能模块在导入时完成自身初始化 (绑定事件/加载数据)
|
||||
import './slots';
|
||||
import './wght';
|
||||
import './metrics';
|
||||
import './apply';
|
||||
import './testFonts';
|
||||
import './home';
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
// metrics.ts — 固定行距/字距 (issue #17)
|
||||
//
|
||||
// 背景: Android 的行高取「paint 度量」与「该行实际使用字体度量」的并集, 只能抬高不能
|
||||
// 压低 (StaticLayout: lineAscent = min(paint 上升部, 该行字体上升部))。因此只要装入
|
||||
// system/fonts 的字体行距各不相同, 换字体行距就会变; 只在家族首位放一个度量载体
|
||||
// 也压不住比它更高的字体。
|
||||
//
|
||||
// 做法: apply.sh 按本页开关与档位, 把装入 system/fonts 的字体行距度量按比例统一到同一
|
||||
// 总量, 并收紧虚高的包围盒 (段落上下留白来自它)。字形完全不动。
|
||||
// 开关存 FONTS/metrics.txt, 档位 (千分比 em) 存 FONTS/line-height.txt。
|
||||
import '@material/web/switch/switch.js';
|
||||
import { exec, toast } from './ksu';
|
||||
import { FONTS_DIR } from './constants';
|
||||
|
||||
/** 行距档位: 字身框倍数 (千分比)。与 index.html 的选项、apply.sh 的缺省值对应 */
|
||||
export const LEVEL_COMPACT = 1200;
|
||||
export const LEVEL_STANDARD = 1450;
|
||||
export const LEVEL_LOOSE = 1600;
|
||||
|
||||
const metricsSwitch = document.getElementById('metrics-switch') as any;
|
||||
const metricsSub = document.getElementById('metrics-sub');
|
||||
const levelSelect = document.getElementById('metrics-level-select') as any;
|
||||
const levelSub = document.getElementById('metrics-level-sub');
|
||||
|
||||
/** 当前 UI 开关状态 */
|
||||
export function getSelectedMetrics(): boolean {
|
||||
return Boolean(metricsSwitch?.selected);
|
||||
}
|
||||
|
||||
/** 当前 UI 选择的档位 (千分比 em) */
|
||||
export function getSelectedLevel(): number {
|
||||
const v = Number(levelSelect?.value ?? LEVEL_STANDARD);
|
||||
return v > 0 ? v : LEVEL_STANDARD;
|
||||
}
|
||||
|
||||
/** 写入开关到 FONTS/metrics.txt (apply.sh 读取) */
|
||||
export async function writeMetrics(enabled: boolean): Promise<void> {
|
||||
try {
|
||||
await exec(`echo '${enabled ? 1 : 0}' > '${FONTS_DIR}/metrics.txt'`);
|
||||
} catch {
|
||||
// 忽略写入失败
|
||||
}
|
||||
}
|
||||
|
||||
/** 写入档位到 FONTS/line-height.txt (apply.sh 读取) */
|
||||
export async function writeLevel(total: number): Promise<void> {
|
||||
try {
|
||||
await exec(`echo '${total}' > '${FONTS_DIR}/line-height.txt'`);
|
||||
} catch {
|
||||
// 忽略写入失败
|
||||
}
|
||||
}
|
||||
|
||||
/** 读取开关 (FONTS/metrics.txt), 默认关闭 */
|
||||
async function readMetrics(): Promise<boolean> {
|
||||
try {
|
||||
const { errno, stdout } = await exec(`cat '${FONTS_DIR}/metrics.txt' 2>/dev/null || true`);
|
||||
if (errno === 0) return stdout.trim() === '1';
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 读取档位 (FONTS/line-height.txt), 默认标准档 */
|
||||
async function readLevel(): Promise<number> {
|
||||
try {
|
||||
const { errno, stdout } = await exec(`cat '${FONTS_DIR}/line-height.txt' 2>/dev/null || true`);
|
||||
if (errno === 0) {
|
||||
const n = Number(stdout.trim());
|
||||
if (n >= 1000 && n <= 3000) return n;
|
||||
}
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
return LEVEL_STANDARD;
|
||||
}
|
||||
|
||||
// 档位只在开关打开时有意义: 关闭时置灰
|
||||
function syncLevelEnabled(): void {
|
||||
const on = getSelectedMetrics();
|
||||
if (levelSelect) levelSelect.disabled = !on;
|
||||
if (levelSub) levelSub.classList.toggle('metrics-sub--on', on);
|
||||
if (metricsSub) metricsSub.classList.toggle('metrics-sub--on', on);
|
||||
}
|
||||
|
||||
// 开关/档位改动即落盘 (与字重覆写模式一致), 应用时 apply.sh 按文件内容统一行距。
|
||||
// 立即落盘的好处: 只改设置不重新应用、或随后更新模块时, 继承到的都是最新选择。
|
||||
metricsSwitch?.addEventListener('change', () => {
|
||||
syncLevelEnabled();
|
||||
void writeMetrics(getSelectedMetrics());
|
||||
void writeLevel(getSelectedLevel());
|
||||
toast(
|
||||
getSelectedMetrics()
|
||||
? '已启用固定行距字距,点「应用」后生效'
|
||||
: '已关闭固定行距字距,点「应用」后生效',
|
||||
);
|
||||
});
|
||||
levelSelect?.addEventListener('change', () => {
|
||||
void writeLevel(getSelectedLevel());
|
||||
toast('已改行距档位,点「应用」后生效');
|
||||
});
|
||||
|
||||
async function initMetricsUI(): Promise<void> {
|
||||
const [enabled, level] = await Promise.all([readMetrics(), readLevel()]);
|
||||
if (metricsSwitch) metricsSwitch.selected = enabled;
|
||||
if (levelSelect) levelSelect.value = String(level);
|
||||
syncLevelEnabled();
|
||||
}
|
||||
|
||||
void initMetricsUI();
|
||||
Reference in new issue
Block a user