feat: 完成 DOCX R4 元素级视觉门禁
建立 Chromium、Word 与 WPS 的可编辑内容、段落几何、页眉页脚、封面、媒体和逐页视觉比较链路。 支持封面独立分节、正文页码重启、主题页边距与横向纸张,并将自然分页差异降为诊断项。 修正代码块内边距和折叠表格单元格边框映射,14 套主题生产矩阵与六组布局视觉矩阵通过。
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
MAXIMUM_DOCX_RESOURCE_COUNT,
|
||||
type DocxMediaCapturePlan,
|
||||
type DocxMediaCaptureTarget,
|
||||
type DocxMediaAlignment,
|
||||
type DocxMediaKind,
|
||||
type PagedDocumentPayload
|
||||
} from "@md-to-pdf/core";
|
||||
@@ -93,6 +94,33 @@ function fitElementToContent(
|
||||
return element.getBoundingClientRect();
|
||||
}
|
||||
|
||||
function getMediaAlignment(
|
||||
article: HTMLElement,
|
||||
rect: DOMRect
|
||||
): DocxMediaAlignment {
|
||||
const articleRect = article.getBoundingClientRect();
|
||||
const articleWidth = finitePositive(articleRect.width, rect.width);
|
||||
if (rect.width >= articleWidth - 2) {
|
||||
return "center";
|
||||
}
|
||||
|
||||
const leftScore = Math.abs(rect.left - articleRect.left);
|
||||
const centerScore = Math.abs(
|
||||
(rect.left + rect.right) / 2 -
|
||||
(articleRect.left + articleRect.right) / 2
|
||||
);
|
||||
const rightScore = Math.abs(articleRect.right - rect.right);
|
||||
const minimumScore = Math.min(
|
||||
leftScore,
|
||||
centerScore,
|
||||
rightScore
|
||||
);
|
||||
if (centerScore <= minimumScore + 2) {
|
||||
return "center";
|
||||
}
|
||||
return leftScore <= rightScore ? "left" : "right";
|
||||
}
|
||||
|
||||
function getRasterScale(width: number, height: number) {
|
||||
return Math.min(
|
||||
DOCX_MEDIA_RASTER_SCALE,
|
||||
@@ -179,6 +207,7 @@ export function collectDocxMediaCaptureTargets(
|
||||
...(getCaption(element)
|
||||
? { caption: getCaption(element) }
|
||||
: {}),
|
||||
alignment: getMediaAlignment(article, rect),
|
||||
displayWidthPx: width,
|
||||
displayHeightPx: height,
|
||||
captureX,
|
||||
|
||||
Reference in New Issue
Block a user