feat: 完成 DOCX R4 元素级视觉门禁
建立 Chromium、Word 与 WPS 的可编辑内容、段落几何、页眉页脚、封面、媒体和逐页视觉比较链路。 支持封面独立分节、正文页码重启、主题页边距与横向纸张,并将自然分页差异降为诊断项。 修正代码块内边距和折叠表格单元格边框映射,14 套主题生产矩阵与六组布局视觉矩阵通过。
This commit is contained in:
@@ -25,6 +25,23 @@ function raster(rectangleX: number): PdfPageRaster {
|
||||
};
|
||||
}
|
||||
|
||||
function differentlySizedRaster(width: number, height: number): PdfPageRaster {
|
||||
const canvas = createCanvas(width, height);
|
||||
const context = canvas.getContext("2d");
|
||||
context.fillStyle = "#ffffff";
|
||||
context.fillRect(0, 0, width, height);
|
||||
context.fillStyle = "#111111";
|
||||
context.fillRect(width * 0.25, height * 0.2, width * 0.25, height * 0.4);
|
||||
const png = Uint8Array.from(canvas.toBuffer("image/png"));
|
||||
return {
|
||||
widthPx: width,
|
||||
heightPx: height,
|
||||
dpi: 144,
|
||||
sha256: createHash("sha256").update(png).digest("hex"),
|
||||
png,
|
||||
};
|
||||
}
|
||||
|
||||
describe("PDF 栅格差异", () => {
|
||||
it("相同页面的全部指标为无差异", async () => {
|
||||
const page = raster(10);
|
||||
@@ -50,4 +67,24 @@ describe("PDF 栅格差异", () => {
|
||||
expect(result.artifacts.overlaySha256).toHaveLength(64);
|
||||
expect(result.artifacts.heatmapSha256).toHaveLength(64);
|
||||
});
|
||||
|
||||
it("可按物理页面基线规范化一像素的栅格舍入差", async () => {
|
||||
const result = await comparePageRasters(
|
||||
differentlySizedRaster(80, 100),
|
||||
differentlySizedRaster(81, 101),
|
||||
{
|
||||
targetWidthPx: 80,
|
||||
targetHeightPx: 100,
|
||||
geometryNormalized: true,
|
||||
},
|
||||
);
|
||||
expect(result.metrics).toMatchObject({
|
||||
baselineWidthPx: 80,
|
||||
candidateWidthPx: 81,
|
||||
comparedWidthPx: 80,
|
||||
dimensionsMatch: false,
|
||||
geometryNormalized: true,
|
||||
});
|
||||
expect(result.metrics.meanAbsoluteError).toBeLessThan(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user