release: 发布 v0.6.1 DOCX 视觉一致性修复

新增通用 CSS 到 OOXML 翻译修复,统一字体、字距、精确行距、段落、列表、表格、引用、代码块与行内代码连续性,不引入按主题 ID 分支。

新增 MdTP Mono 并统一 Serif、Sans、Mono 三字体包的 Chromium 与 DOCX 使用链;字体声明、嵌入部件和 Word/WPS 实际采用均进入硬门禁。

重建封面整页及正文语义块视觉差分,14 套主题、纵横两个方向、五组页边距共 140 个真实场景全部通过,阻断失败和诊断失败均为零。

源码服务、Docker Web API 与实际安装 Desktop 的 red-briefing 导出均包含 5 个字体部件;Word/WPS 原生渲染和逐页复核通过。修复 Docker 构建上下文与运行层复用软链接,并完善 v0.6.1 版本、发行说明和发布归集。

验证:npm test(116 个文件、616 项测试)、npm run typecheck、npm run build、git diff --check 全部通过。Desktop 安装器与 ZIP、Docker v0.6.1 镜像已生成;Windows 产物仍为未签名内部发行。
This commit is contained in:
SkyJourney
2026-08-04 10:30:44 +08:00
parent b275c671fc
commit 2c5c1bd317
84 changed files with 4404 additions and 344 deletions
+1
View File
@@ -25,6 +25,7 @@
"@md-to-pdf/docx-engine": "0.1.0",
"@md-to-pdf/docx-theme-engine": "0.1.0",
"@md-to-pdf/font-pack-registry": "0.1.0",
"@md-to-pdf/preview-engine": "0.1.0",
"@md-to-pdf/renderer": "0.1.0"
},
"devDependencies": {
@@ -197,6 +197,7 @@ export async function prepareDocxMedia(
...parsedPlan.data.echartsErrors,
...parsedPlan.data.mermaidErrors
],
totalBytes
totalBytes,
documentLayout: parsedPlan.data.documentLayout ?? { tables: [] }
};
}
@@ -11,6 +11,7 @@ import {
type DocxThemeStyleSnapshot
} from "@md-to-pdf/docx-theme-engine";
import type { PreparedDocxExport } from "./application-service.js";
import { SHARED_HIGHLIGHT_CSS } from "@md-to-pdf/preview-engine";
export interface PreparedDocxThemeTokens {
tokens: DocxThemeTokenSet;
@@ -67,7 +68,7 @@ export class DocxThemeTokenService
const themeFingerprint =
await createDocxThemeStyleFingerprint(
prepared.theme.manifest.id,
prepared.theme.css
`${SHARED_HIGHLIGHT_CSS}\n${prepared.theme.css}`
);
signal?.throwIfAborted();
const snapshot =
@@ -80,7 +81,7 @@ export class DocxThemeTokenService
{
themeId: prepared.theme.manifest.id,
themeFingerprint,
themeCss: prepared.theme.css,
themeCss: `${SHARED_HIGHLIGHT_CSS}\n${prepared.theme.css}`,
baseUrl: this.adapter.themeStyleBaseUrl
},
signal
+53 -3
View File
@@ -92,6 +92,48 @@ const maximumCssImportDepth = 8;
const sharedThemeAssetId = "_shared";
const sharedThemeAssetScheme = "theme-shared:";
const sharedFontCssPath = "official-fonts/fonts.css";
const engineCodeFontFaces: readonly DocxFontFace[] = [
{
family: "MdTP Mono",
aliases: [
"Cascadia Mono",
"Cascadia Code",
"Consolas",
"Lucida Console",
"SFMono-Regular",
"Menlo",
"Monaco",
"Courier New",
"Courier",
"Source Code Pro",
"JetBrains Mono"
],
source: "fonts/mdtp-mono.ttf",
weight: 400,
style: "normal",
license: "OFL-1.1"
},
{
family: "MdTP Mono",
aliases: [
"Cascadia Mono",
"Cascadia Code",
"Consolas",
"Lucida Console",
"SFMono-Regular",
"Menlo",
"Monaco",
"Courier New",
"Courier",
"Source Code Pro",
"JetBrains Mono"
],
source: "fonts/mdtp-mono-bold.ttf",
weight: 700,
style: "normal",
license: "OFL-1.1"
}
];
function isMissingFileError(error: unknown) {
return (
@@ -434,7 +476,8 @@ export function createThemeRegistry(options: ThemeRegistryOptions) {
async function resolveThemeFontPacks(theme: ThemeRecord) {
const registry = await listFontPacks();
const faces = theme.manifest.docxFonts?.faces ?? [];
const declaredFaces = theme.manifest.docxFonts?.faces ?? [];
const faces = [...declaredFaces, ...engineCodeFontFaces];
const requests: FontPackFaceRequest[] = faces.map((face) => ({
family: face.family,
aliases: face.aliases,
@@ -453,7 +496,14 @@ export function createThemeRegistry(options: ThemeRegistryOptions) {
matches.set(face, match);
}
}
return { registry, resolution, matches };
return {
registry,
resolution,
matches,
faces: faces.filter(
(face) => declaredFaces.includes(face) || matches.has(face)
)
};
}
function createFontPackCss(
@@ -711,8 +761,8 @@ export function createThemeRegistry(options: ThemeRegistryOptions) {
if (!theme) {
return undefined;
}
const faces = theme.manifest.docxFonts?.faces ?? [];
const fontPacks = await resolveThemeFontPacks(theme);
const faces = fontPacks.faces;
const fonts = await Promise.all(
faces.map(async (face) => {
const matched = fontPacks.matches.get(face);
@@ -132,7 +132,11 @@ function sha256(content: Uint8Array | string) {
}
async function createFontPackFixture(
options: { corruptWebHash?: boolean; minimumAppVersion?: string } = {}
options: {
corruptWebHash?: boolean;
minimumAppVersion?: string;
targets?: string[];
} = {}
) {
const root = join(temporaryDirectory!, "font-packs");
const directory = join(root, "test-font-pack", "1.0.0");
@@ -162,7 +166,7 @@ async function createFontPackFixture(
faces: [
{
id: "test-regular",
targets: ["Test"],
targets: options.targets ?? ["Test"],
weight: 400,
style: "normal",
web: {
@@ -464,6 +468,53 @@ describe("共享应用服务", () => {
});
});
it("以引擎级代码字体请求为新主题注入同源等宽字体", async () => {
const roots = await createThemeFixture();
const fontPack = await createFontPackFixture({
targets: ["MdTP Mono", "Cascadia Code", "Consolas"]
});
const service = createApplicationService({
...roots,
fontPacks: {
roots: [fontPack.root],
appVersion: "0.6.0",
createAssetUrl: (packId, version, faceId, kind, hash) =>
`mdpdf://font-pack/${packId}/${version}/${faceId}/${kind}?v=${hash}`
}
});
const css = await service.getThemeCss("test-theme");
expect(css).toContain('font-family: "Cascadia Code";');
expect(css).toContain('font-family: "Consolas";');
const prepared = await service.prepareDocxExport({
markdown: "`inline()`",
fileName: "代码.md",
exportConfig: {
...defaultExportConfig,
themeId: "test-theme"
}
});
expect(prepared.theme.fonts).toEqual(
expect.arrayContaining([
expect.objectContaining({
family: "MdTP Mono",
aliases: expect.arrayContaining(["Cascadia Code", "Consolas"]),
source: "font-pack:test-font-pack/1.0.0/test-regular/docx",
content: new Uint8Array(fontPack.docx)
})
])
);
expect(prepared.theme.fontPack?.appliedFaces).toEqual(
expect.arrayContaining([
expect.objectContaining({
family: "MdTP Mono",
packId: "test-font-pack",
faceId: "test-regular"
})
])
);
});
it("字体包损坏时记录诊断并回退到主题字体", async () => {
const roots = await createThemeFixture();
const fontPack = await createFontPackFixture({ corruptWebHash: true });