feat: 实现 DOCX 可编辑字体嵌入

This commit is contained in:
SkyJourney
2026-07-31 16:18:30 +08:00
parent f3847f3e4b
commit 10bc62cee4
32 changed files with 2195 additions and 76 deletions
+74
View File
@@ -57,4 +57,78 @@ describe("主题清单", () => {
showOnFirstPage: false
});
});
it("允许声明可嵌入的本地 DOCX 字体字形面", () => {
const parsed = themeManifestSchema.parse({
manifestVersion: 1,
id: "font-test",
name: "字体测试主题",
version: "0.6.0",
description: "测试可移植 DOCX 字体声明。",
author: "md-to-pdf contributors",
license: "项目自有",
entry: "theme.css",
domPreset: "generic",
defaultFontSize: "16px",
supportedFeatures: [],
docxFonts: {
faces: [
{
family: "Mdpdf Fandol Fang",
aliases: ["FangSong", "STFangsong"],
source:
"theme-shared:official-fonts/FandolFang-Regular.woff2",
weight: 400,
style: "normal",
license: "GPL-3.0-with-font-exception"
}
]
},
bundled: true
});
expect(parsed.docxFonts?.faces[0]).toMatchObject({
family: "Mdpdf Fandol Fang",
weight: 400,
style: "normal"
});
});
it("拒绝远程或越界的 DOCX 字体资源", () => {
const base = {
manifestVersion: 1,
id: "font-test",
name: "字体测试主题",
version: "0.6.0",
description: "测试字体路径门禁。",
author: "md-to-pdf contributors",
license: "项目自有",
entry: "theme.css",
domPreset: "generic",
defaultFontSize: "16px",
supportedFeatures: [],
bundled: true
};
for (const source of [
"https://example.com/font.woff2",
"../font.woff2",
"C:\\fonts\\font.ttf"
]) {
expect(() =>
themeManifestSchema.parse({
...base,
docxFonts: {
faces: [
{
family: "Unsafe Font",
source,
license: "unknown"
}
]
}
})
).toThrow();
}
});
});