mirror of
https://github.com/YuleBest/FontMM.git
synced 2026-12-04 03:11:48 +08:00
feat(webui): 字重范围覆写 fonts.xml — 裁切/平均分配两种模式
- 新增 web/src/fontsXml.ts: generateSansSerifFamily / applyWghtMode (字符串级 替换 sans-serif family 段, 保留 #ifdef 注释与格式) + fast-xml-parser 校验 - 配置页新增「字重覆写模式」: 不处理 / 裁切粗细等级 / 平均分配字重 (模式持久化到 FONTS/wght-mode.txt, 无可变字体时禁用提示) - 应用时覆写流程: 从 hans/hant/en 收集 wght 范围 (emoji/mono 除外), 多可变取跨度最小者; cp fonts.xml -> fetch -> 替换 -> base64 分块写回 模块 system/etc/fonts.xml; 无可变或模式 0 时跳过, 失败不阻断应用 - 平均分配: 400 固定, 两端按范围线性插值 (floor); 裁切: 仅保留范围内的字重 - README 特性与使用说明更新
This commit is contained in:
1 parent
418ea6e7c6
commit
2ec6c45c80
8 files changed
+296
No files matched your search
@@ -14,6 +14,7 @@ FontMM 是一个用于在 ColorOS 设备上一键更换系统字体的 **Magisk
|
||||
- **可视化文件选择器**:浏览设备目录、仅显示 `.ttf` 文件
|
||||
- **安装自检**:刷入时自动校验 ColorOS 版本、KernelSU 元模块、FontLoader 版本
|
||||
- **更新模式**:覆盖安装/更新模块时自动继承旧版模块中已设置的字体
|
||||
- **字重范围覆写**:可变字体 wght 范围与实际字重等级不符时(如 MiSansVF 150-700),可选择「裁切粗细等级」或「平均分配字重」两种方式覆写 `fonts.xml` 的 sans-serif 配置,保证 9 档字重均有正确映射(多槽位可变字体时自动取跨度最小者)
|
||||
- **补充字库**:内置 OFL/MIT 许可字体,兜底 CJK 扩展区、最新 Unicode 字符与小篆(Seal)等罕见字形
|
||||
|
||||
## 支持环境
|
||||
@@ -65,6 +66,8 @@ FontMM 是一个用于在 ColorOS 设备上一键更换系统字体的 **Magisk
|
||||
3. 点击「应用字体」,弹窗展示完整应用日志
|
||||
4. **重启设备**后生效
|
||||
|
||||
> **字重覆写**(可选):当所选字体为可变字体且 wght 轴范围不满 100-900(如 MiSansVF 150-700)时,可在配置页「字重覆写模式」选择处理方式——**不处理**(默认,超出范围的字重由系统 clamp)/ **裁切粗细等级**(删除范围外的字重条目,交给系统 fallback)/ **平均分配字重**(保留 9 档,400 不变,两端按范围平均插值)。仅当已选择可变字体(中文/繁体/英文任一)时可用。
|
||||
|
||||
### 手动放置字体(可选)
|
||||
|
||||
1. 把字体放入 `/data/adb/modules/FontMM/FONTS/`,命名规则:
|
||||
|
||||
@@ -99,6 +99,21 @@
|
||||
<!-- 配置视图 -->
|
||||
<main id="config-view" class="view view-config">
|
||||
<div class="home-title">字体配置</div>
|
||||
|
||||
<div class="wght-mode-row">
|
||||
<div class="wght-mode-info">
|
||||
<div class="wght-mode-title">字重覆写模式</div>
|
||||
<div class="wght-mode-sub" id="wght-mode-sub">
|
||||
可变字体 wght 范围与实际字重等级不符时, 按所选方式覆写 sans-serif 配置
|
||||
</div>
|
||||
</div>
|
||||
<md-outlined-select id="wght-mode-select" label="覆写模式">
|
||||
<md-select-option value="0" selected>不处理</md-select-option>
|
||||
<md-select-option value="1">裁切粗细等级</md-select-option>
|
||||
<md-select-option value="2">平均分配字重</md-select-option>
|
||||
</md-outlined-select>
|
||||
</div>
|
||||
|
||||
<div id="slots"></div>
|
||||
</main>
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@material/web": "^2.4.1",
|
||||
"fast-xml-parser": "^5.10.1",
|
||||
"kernelsu": "^3.0.2",
|
||||
"material-symbols": "^0.28.0",
|
||||
"opentype.js": "^2.0.0",
|
||||
|
||||
Generated
+58
@@ -11,6 +11,9 @@ importers:
|
||||
'@material/web':
|
||||
specifier: ^2.4.1
|
||||
version: 2.5.0
|
||||
fast-xml-parser:
|
||||
specifier: ^5.10.1
|
||||
version: 5.10.1
|
||||
kernelsu:
|
||||
specifier: ^3.0.2
|
||||
version: 3.0.2
|
||||
@@ -210,6 +213,9 @@ packages:
|
||||
'@material/web@2.5.0':
|
||||
resolution: {integrity: sha512-x2Uovyq8E/Zc1xHXd9s1eBMXF5pMHVAt70pISKd0fL3Ajj4L6zQaQUY/awcfR2RDAMKXC7i4+vr0arv1YaOR/g==}
|
||||
|
||||
'@nodable/entities@3.0.0':
|
||||
resolution: {integrity: sha512-8L9xFeTYKhm49xfIypoe2W5wV1m/3Z58kT+7kR9A8OyFxcPduI4VmxaUMQyKYrRjUoLLSXv6EKKID5Tvj9cUVw==}
|
||||
|
||||
'@oxfmt/binding-android-arm-eabi@0.61.0':
|
||||
resolution: {integrity: sha512-BaS+1OVvg9sr+Xav0+KdWedQRcAzrdoEcwMZeqoc2F6ieC1s/t5eM35YQoRPQ7vAqkZ+p3tbQb1r9I9mrV5oGA==}
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
@@ -683,6 +689,9 @@ packages:
|
||||
'@types/trusted-types@2.0.7':
|
||||
resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
|
||||
|
||||
anynum@1.0.1:
|
||||
resolution: {integrity: sha512-N6//FLET/tXYNM/F6ABca1oH6fWB+KlTt909Le28WMDBk8oaT4vY17DCrwg2MvmuqUKt3Ni4N5dGJ/EoBgcO6A==}
|
||||
|
||||
chokidar@5.0.0:
|
||||
resolution: {integrity: sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==}
|
||||
engines: {node: '>= 20.19.0'}
|
||||
@@ -696,6 +705,13 @@ packages:
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
fast-xml-builder@1.3.0:
|
||||
resolution: {integrity: sha512-F74cZEdCvuw9P41GAC3rod4X04jjWGM1JPEv/GWSqFTWLsdyMSBMBMlm9Hk3GLBgLBbdBNY8yee0pQh2RBVESQ==}
|
||||
|
||||
fast-xml-parser@5.10.1:
|
||||
resolution: {integrity: sha512-IEMIf7298kXuZSRFoGfMYrl7is8LpavODgbNz1cwIudv7KwVFnuU+UsMporfq6PD6aXSlawZlARiA3UywCTfMw==}
|
||||
hasBin: true
|
||||
|
||||
fdir@6.5.0:
|
||||
resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
@@ -721,6 +737,9 @@ packages:
|
||||
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
is-unsafe@2.0.0:
|
||||
resolution: {integrity: sha512-2LdV822R+wmI86unXA93WCFpL6g+av8ynWk0nrHyJqGop5VoocYsSLFgN8jrfalT6iGeLNM4KXuVSsULP53kEA==}
|
||||
|
||||
kernelsu@3.0.2:
|
||||
resolution: {integrity: sha512-3MTGgIbl3TWCzqnJP6Fun9tHv6VULR3O188U3raeGRSMzK+G3pldL9ySwaZWhsHCtI2BTvlQuu/3p10s4a5c3w==}
|
||||
|
||||
@@ -774,6 +793,10 @@ packages:
|
||||
vite-plus:
|
||||
optional: true
|
||||
|
||||
path-expression-matcher@1.6.2:
|
||||
resolution: {integrity: sha512-enSlaiat05iasnzmgNxRj8reFdj3puY2QpNgP1aPIaVfT6nn9ICuPoFlKHk8EN22HcwewshO+mN2DGbkCEOtqQ==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
|
||||
picocolors@1.1.1:
|
||||
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
|
||||
|
||||
@@ -807,6 +830,9 @@ packages:
|
||||
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
strnum@2.4.1:
|
||||
resolution: {integrity: sha512-M9eUSMT2dCB2cTNPG7UYj6KuK7RJR2SN2+yCV/fTW3xzTCS6EaGZ5pSMgDIjB7r8zSfTGk+dvvn9rTjpVS9Mwg==}
|
||||
|
||||
tinyglobby@0.2.17:
|
||||
resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
@@ -875,6 +901,10 @@ packages:
|
||||
utf-8-validate:
|
||||
optional: true
|
||||
|
||||
xml-naming@0.3.0:
|
||||
resolution: {integrity: sha512-ghig2TBE/H11aOVgmahA3MhimvkBr6JIYknH/Dhdk10nXwdbIqBJsbfMxpvFPG8bAw77gN29aQWvKpmVoPlvPQ==}
|
||||
engines: {node: '>=16.0.0'}
|
||||
|
||||
snapshots:
|
||||
|
||||
'@esbuild/aix-ppc64@0.25.12':
|
||||
@@ -971,6 +1001,8 @@ snapshots:
|
||||
lit: 3.3.3
|
||||
tslib: 2.8.1
|
||||
|
||||
'@nodable/entities@3.0.0': {}
|
||||
|
||||
'@oxfmt/binding-android-arm-eabi@0.61.0':
|
||||
optional: true
|
||||
|
||||
@@ -1223,6 +1255,8 @@ snapshots:
|
||||
|
||||
'@types/trusted-types@2.0.7': {}
|
||||
|
||||
anynum@1.0.1: {}
|
||||
|
||||
chokidar@5.0.0:
|
||||
dependencies:
|
||||
readdirp: 5.0.0
|
||||
@@ -1259,6 +1293,20 @@ snapshots:
|
||||
'@esbuild/win32-ia32': 0.25.12
|
||||
'@esbuild/win32-x64': 0.25.12
|
||||
|
||||
fast-xml-builder@1.3.0:
|
||||
dependencies:
|
||||
path-expression-matcher: 1.6.2
|
||||
xml-naming: 0.3.0
|
||||
|
||||
fast-xml-parser@5.10.1:
|
||||
dependencies:
|
||||
'@nodable/entities': 3.0.0
|
||||
fast-xml-builder: 1.3.0
|
||||
is-unsafe: 2.0.0
|
||||
path-expression-matcher: 1.6.2
|
||||
strnum: 2.4.1
|
||||
xml-naming: 0.3.0
|
||||
|
||||
fdir@6.5.0(picomatch@4.0.5):
|
||||
optionalDependencies:
|
||||
picomatch: 4.0.5
|
||||
@@ -1276,6 +1324,8 @@ snapshots:
|
||||
is-extglob: 2.1.1
|
||||
optional: true
|
||||
|
||||
is-unsafe@2.0.0: {}
|
||||
|
||||
kernelsu@3.0.2: {}
|
||||
|
||||
lit-element@4.2.2:
|
||||
@@ -1349,6 +1399,8 @@ snapshots:
|
||||
'@oxlint/binding-win32-ia32-msvc': 1.76.0
|
||||
'@oxlint/binding-win32-x64-msvc': 1.76.0
|
||||
|
||||
path-expression-matcher@1.6.2: {}
|
||||
|
||||
picocolors@1.1.1: {}
|
||||
|
||||
picomatch@4.0.5: {}
|
||||
@@ -1410,6 +1462,10 @@ snapshots:
|
||||
|
||||
source-map-js@1.2.1: {}
|
||||
|
||||
strnum@2.4.1:
|
||||
dependencies:
|
||||
anynum: 1.0.1
|
||||
|
||||
tinyglobby@0.2.17:
|
||||
dependencies:
|
||||
fdir: 6.5.0(picomatch@4.0.5)
|
||||
@@ -1434,3 +1490,5 @@ snapshots:
|
||||
sass: 1.102.0
|
||||
|
||||
ws@8.21.2: {}
|
||||
|
||||
xml-naming@0.3.0: {}
|
||||
@@ -0,0 +1,62 @@
|
||||
// fontsXml.ts — 字重范围覆写 fonts.xml 的 sans-serif family 段
|
||||
// 覆写采用字符串级替换 (保留文件全部 #ifdef 注释与格式), fast-xml-parser 仅用于结果校验
|
||||
import { XMLValidator } from 'fast-xml-parser';
|
||||
|
||||
/** 覆写模式: 0=不处理 1=裁切粗细等级 2=平均分配字重 */
|
||||
export type WghtMode = 0 | 1 | 2;
|
||||
|
||||
export const WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900];
|
||||
|
||||
/** 平均分配: 计算 weight w 对应的 axis wght 值 (400 固定, 两端线性插值, 向下取整) */
|
||||
export function averagedAxis(min: number, max: number, w: number): number {
|
||||
if (w === 400) return 400;
|
||||
if (w < 400) return Math.floor(min + ((400 - min) * (w - 100)) / 300);
|
||||
return Math.floor(400 + ((max - 400) * (w - 400)) / 500);
|
||||
}
|
||||
|
||||
/** 生成单条 <font> 条目 (缩进与现有 fonts.xml 一致) */
|
||||
function fontEntry(weight: number, axisWght: number): string {
|
||||
return ` <font weight="${weight}" style="normal">SysFont-Regular.ttf
|
||||
<axis tag="ital" stylevalue="0" />
|
||||
<axis tag="wdth" stylevalue="100" />
|
||||
<axis tag="wght" stylevalue="${axisWght}" />
|
||||
</font>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 sans-serif family 段
|
||||
* @param mode 1=裁切 (仅保留 weight ∈ [min,max]) 2=平均 (全保留, axis 按范围插值)
|
||||
*/
|
||||
export function generateSansSerifFamily(min: number, max: number, mode: 1 | 2): string {
|
||||
const kept = mode === 1 ? WEIGHTS.filter((w) => w >= min && w <= max) : WEIGHTS;
|
||||
const lines = kept.map((w) => {
|
||||
const axisWght = mode === 2 ? averagedAxis(min, max, w) : w;
|
||||
return fontEntry(w, axisWght);
|
||||
});
|
||||
return ` <family name="sans-serif">\n${lines.join('\n')}\n </family>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在完整 fonts.xml 文本中替换 sans-serif family 段
|
||||
* mode=0 或无范围时原样返回
|
||||
*/
|
||||
export function applyWghtMode(xml: string, mode: WghtMode, min?: number, max?: number): string {
|
||||
if (mode === 0 || min === undefined || max === undefined) return xml;
|
||||
const startTag = '<family name="sans-serif">';
|
||||
const start = xml.indexOf(startTag);
|
||||
if (start < 0) return xml;
|
||||
const end = xml.indexOf('</family>', start);
|
||||
if (end < 0) return xml;
|
||||
const before = xml.slice(0, start);
|
||||
const after = xml.slice(end + '</family>'.length);
|
||||
return before + generateSansSerifFamily(min, max, mode) + after;
|
||||
}
|
||||
|
||||
/** 校验 XML 合法性 (fast-xml-parser) */
|
||||
export function validateXml(xml: string): boolean {
|
||||
try {
|
||||
return XMLValidator.validate(xml) === true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,14 @@ async function mockExec(command: string): Promise<ExecResult> {
|
||||
if (command.includes('apply.sh')) {
|
||||
return fake('[*] 安装: SysSans-Hans-Regular.ttf (模拟)\n[*] 全部完成, 重启后生效 (模拟)');
|
||||
}
|
||||
// 字重覆写模式: cat 返回已选 '1' (裁切), echo 写入模拟成功
|
||||
if (command.includes('wght-mode.txt')) {
|
||||
return command.includes('echo') ? fake('') : slow('1');
|
||||
}
|
||||
// 覆写 fonts.xml: cp 模拟成功 (fetch work/fonts.xml 在 dev 下 404, 覆写被跳过, 不阻断应用)
|
||||
if (command.includes('fonts.xml')) {
|
||||
return slow('');
|
||||
}
|
||||
|
||||
// 元模块 (KernelSU 3.0+ 需要): 模拟已安装
|
||||
if (command.includes('metamodule')) {
|
||||
|
||||
+117
@@ -29,6 +29,7 @@ import {
|
||||
} from './ksu';
|
||||
import { FontFilePicker } from './fontPicker';
|
||||
import { FontEditorToolDef, MiFontToolDef, ToolHost } from './tools';
|
||||
import { applyWghtMode } from './fontsXml';
|
||||
import type { FontSlot } from './types';
|
||||
import * as opentype from 'opentype.js';
|
||||
|
||||
@@ -72,6 +73,9 @@ const slots: Record<'hans' | 'hant' | 'en' | 'mono' | 'emoji', FontSlot> = {
|
||||
};
|
||||
|
||||
const slotsEl = document.getElementById('slots')!;
|
||||
// 字重覆写模式选择 (声明提前: renderSlots 首轮调用会访问)
|
||||
const wghtModeSelect = document.getElementById('wght-mode-select') as any;
|
||||
const wghtModeSub = document.getElementById('wght-mode-sub');
|
||||
const applyBtn = document.getElementById('apply-btn') as HTMLButtonElement;
|
||||
const logDialog = document.getElementById('log-dialog') as any;
|
||||
const logContent = document.getElementById('log-content')!;
|
||||
@@ -270,6 +274,7 @@ function renderSlots() {
|
||||
applyBtn.style.display = !slots.hans.path ? 'none' : '';
|
||||
applyBtn.disabled = applying;
|
||||
}
|
||||
updateWghtModeDisabled();
|
||||
}
|
||||
|
||||
async function copyFont(src: string, dest: string) {
|
||||
@@ -277,11 +282,88 @@ async function copyFont(src: string, dest: string) {
|
||||
if (errno !== 0) throw new Error(`复制失败: ${stderr}`);
|
||||
}
|
||||
|
||||
// 选择用于覆写的 wght 范围: 从 hans/hant/en 收集 (emoji/mono 除外), 取跨度最小者; 无可变返回 null
|
||||
function pickWghtRange(): { min: number; max: number } | null {
|
||||
let best: { min: number; max: number } | null = null;
|
||||
let bestSpan = Infinity;
|
||||
for (const key of ['hans', 'hant', 'en'] as const) {
|
||||
const r = slots[key]?.wghtRange;
|
||||
if (!r) continue;
|
||||
const m = r.match(/^(\d+)-(\d+)$/);
|
||||
if (!m) continue;
|
||||
const min = Number(m[1]);
|
||||
const max = Number(m[2]);
|
||||
const span = max - min;
|
||||
if (span < bestSpan) {
|
||||
bestSpan = span;
|
||||
best = { min, max };
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// 读取字重覆写模式 (FONTS/wght-mode.txt), 默认 0 不处理
|
||||
async function readWghtMode(): Promise<0 | 1 | 2> {
|
||||
try {
|
||||
const { errno, stdout } = await exec(`cat '${FONTS_DIR}/wght-mode.txt' 2>/dev/null || true`);
|
||||
if (errno === 0) {
|
||||
const n = Number(stdout.trim());
|
||||
if (n === 1 || n === 2) return n as 0 | 1 | 2;
|
||||
}
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function bytesToBase64(bytes: Uint8Array): string {
|
||||
let s = '';
|
||||
for (let i = 0; i < bytes.length; i += 0x8000) {
|
||||
s += btoa(String.fromCharCode(...bytes.subarray(i, i + 0x8000)));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// 覆写模块 fonts.xml 的 sans-serif family 段: cp -> fetch -> 字符串替换 -> base64 分块写回
|
||||
async function applyWghtOverride(mode: 1 | 2, min: number, max: number): Promise<void> {
|
||||
const modXml = '/data/adb/modules/FontMM/system/etc/fonts.xml';
|
||||
const tmp = `${WEBROOT_DIR}/work/fonts.new.xml`;
|
||||
try {
|
||||
await exec(
|
||||
`mkdir -p '${WEBROOT_DIR}/work' && cp -f '${modXml}' '${WEBROOT_DIR}/work/fonts.xml'`,
|
||||
);
|
||||
const res = await fetch('work/fonts.xml');
|
||||
if (!res.ok) throw new Error(`读取 fonts.xml 失败 (${res.status})`);
|
||||
const xml = await res.text();
|
||||
const replaced = applyWghtMode(xml, mode, min, max);
|
||||
if (replaced === xml) return; // 无变化 (mode 0 或无 sans-serif family)
|
||||
const b64 = bytesToBase64(new TextEncoder().encode(replaced));
|
||||
await exec(`rm -f '${tmp}'`);
|
||||
const CHUNK = 30000;
|
||||
for (let i = 0; i < b64.length; i += CHUNK) {
|
||||
const part = b64.slice(i, i + CHUNK);
|
||||
await exec(`echo '${part}' | base64 -d >> '${tmp}'`);
|
||||
}
|
||||
await exec(`cp -f '${tmp}' '${modXml}'`);
|
||||
} catch (e) {
|
||||
// 覆写失败不阻断应用主流程
|
||||
console.warn('字重范围覆写失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
if (!slots.hans.path) return;
|
||||
applying = true;
|
||||
renderSlots();
|
||||
try {
|
||||
// 字重范围覆写: 用 UI 当前模式 (持久化到 FONTS/wght-mode.txt), 仅当存在可变字体且模式非 0 时处理
|
||||
const wghtMode = (Number(wghtModeSelect?.value ?? 0) || 0) as 0 | 1 | 2;
|
||||
await writeWghtMode(wghtMode);
|
||||
const wghtPick = pickWghtRange();
|
||||
if (wghtMode !== 0 && wghtPick) {
|
||||
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`);
|
||||
@@ -340,6 +422,41 @@ async function apply() {
|
||||
applyBtn?.addEventListener('click', apply);
|
||||
renderSlots();
|
||||
|
||||
// ---------------- 字重覆写模式选择 ----------------
|
||||
|
||||
// 写入模式到 FONTS/wght-mode.txt
|
||||
async function writeWghtMode(mode: 0 | 1 | 2): Promise<void> {
|
||||
try {
|
||||
await exec(`echo '${mode}' > '${FONTS_DIR}/wght-mode.txt'`);
|
||||
} catch {
|
||||
// 忽略写入失败
|
||||
}
|
||||
}
|
||||
|
||||
// 回填模式选择
|
||||
async function initWghtModeUI(): Promise<void> {
|
||||
const mode = await readWghtMode();
|
||||
if (wghtModeSelect) wghtModeSelect.value = String(mode);
|
||||
updateWghtModeDisabled();
|
||||
}
|
||||
|
||||
// 根据是否有可变字体决定是否禁用 (emoji/mono 不计入)
|
||||
function updateWghtModeDisabled(): void {
|
||||
const hasVar = ['hans', 'hant', 'en'].some((k) => slots[k as 'hans']?.isVariable);
|
||||
if (wghtModeSelect) wghtModeSelect.disabled = !hasVar;
|
||||
if (wghtModeSub) {
|
||||
wghtModeSub.textContent = hasVar
|
||||
? '可变字体 wght 范围与实际字重等级不符时, 按所选方式覆写 sans-serif 配置'
|
||||
: '当前未选择可变字体 (中文/繁体/英文), 此功能不可用';
|
||||
}
|
||||
}
|
||||
|
||||
wghtModeSelect?.addEventListener('change', () => {
|
||||
const v = Number(wghtModeSelect.value);
|
||||
if (v === 0 || v === 1 || v === 2) void writeWghtMode(v as 0 | 1 | 2);
|
||||
});
|
||||
void initWghtModeUI();
|
||||
|
||||
// ---------------- 导航与视图切换 ----------------
|
||||
const homeView = document.getElementById('home-view')!;
|
||||
const configView = document.getElementById('config-view')!;
|
||||
|
||||
@@ -1141,3 +1141,35 @@ md-dialog {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
// ---- 字重覆写模式选择 ----
|
||||
.wght-mode-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
padding: 14px 16px;
|
||||
border-radius: var(--md-shape-corner-large);
|
||||
background: var(--md-sys-color-surface-container-low);
|
||||
|
||||
.wght-mode-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.wght-mode-title {
|
||||
font-size: var(--md-sys-typescale-title-medium-size);
|
||||
font-weight: var(--md-sys-typescale-title-medium-weight);
|
||||
}
|
||||
|
||||
.wght-mode-sub {
|
||||
font-size: var(--md-sys-typescale-body-small-size);
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
md-outlined-select {
|
||||
flex-shrink: 0;
|
||||
min-width: 150px;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user