新增通用 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 产物仍为未签名内部发行。
77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
aggregatePdfTextLines,
|
|
buildPageContentText,
|
|
normalizePdfEditableText,
|
|
normalizePdfText,
|
|
type PdfTextItemSnapshot,
|
|
} from "../src/index.js";
|
|
|
|
function item(
|
|
text: string,
|
|
x: number,
|
|
y: number,
|
|
width = 20,
|
|
height = 10,
|
|
): PdfTextItemSnapshot {
|
|
return {
|
|
text,
|
|
normalizedText: normalizePdfText(text),
|
|
bounds: { x, y, width, height },
|
|
baselineY: y + height,
|
|
hasEol: false,
|
|
};
|
|
}
|
|
|
|
describe("PDF 文本行聚合", () => {
|
|
it("按坐标聚合中文文本并规范化兼容字符", () => {
|
|
const lines = aggregatePdfTextLines(
|
|
[
|
|
item("ABC", 10, 100, 30),
|
|
item("中文", 41, 100, 20),
|
|
item("第二行", 10, 120, 40),
|
|
],
|
|
842,
|
|
);
|
|
expect(lines.map((line) => line.normalizedText)).toEqual([
|
|
"ABC中文",
|
|
"第二行",
|
|
]);
|
|
});
|
|
|
|
it("将字体 ToUnicode 中的传统户部件归一为简体字符", () => {
|
|
expect(normalizePdfText("戶⼾")).toBe("户户");
|
|
expect(normalizePdfText("⻅⻆⻓⻔⻚⻛")).toBe("见角长门页风");
|
|
});
|
|
|
|
it("从可编辑正文契约中移除 Word 自动列表装饰符", () => {
|
|
expect(normalizePdfEditableText("• 项目一 ◦ 子项 ▪ 末项 WPS")).toBe(
|
|
"项目一子项末项WPS"
|
|
);
|
|
});
|
|
|
|
it("只在页眉页脚坐标带识别独立页码", () => {
|
|
const lines = aggregatePdfTextLines(
|
|
[
|
|
item("章节 1", 72, 400, 50),
|
|
item("— 1 —", 280, 731, 35, 14),
|
|
],
|
|
842,
|
|
);
|
|
expect(lines.map((line) => line.role)).toEqual([
|
|
"content",
|
|
"page-number",
|
|
]);
|
|
expect(buildPageContentText(lines)).toBe("章节 1");
|
|
});
|
|
|
|
it("不会把页脚中的普通说明误判为页码", () => {
|
|
const lines = aggregatePdfTextLines(
|
|
[item("内部资料 1", 72, 800, 70)],
|
|
842,
|
|
);
|
|
expect(lines[0]?.role).toBe("content");
|
|
});
|
|
});
|