优化预览与导出排版

This commit is contained in:
iqudoo
2026-06-12 20:07:49 +08:00
parent 7ad1f59ae1
commit c9a187bf9b
7 changed files with 291 additions and 116 deletions

View File

@@ -151,6 +151,60 @@ export const DEFAULT_CUT_LINE_CONFIG: CutLineConfig = {
color: '#cccccc',
};
export interface GridCutLinePositions {
xs: number[];
ys: number[];
gridW: number;
gridH: number;
}
/** 收集网格裁切线坐标(去重),每条线只绘制一次,避免转角/外缘叠线变粗 */
export function collectGridCutLinePositions(
originX: number,
originY: number,
labelW: number,
labelH: number,
gridCols: number,
gridRows: number,
columnGap: number,
rowGap: number
): GridCutLinePositions {
const gridW = gridCols * labelW + Math.max(0, gridCols - 1) * columnGap;
const gridH = gridRows * labelH + Math.max(0, gridRows - 1) * rowGap;
const xs = new Set<number>();
const ys = new Set<number>();
for (let c = 0; c < gridCols; c++) {
xs.add(originX + c * (labelW + columnGap));
xs.add(originX + c * (labelW + columnGap) + labelW);
}
for (let r = 0; r < gridRows; r++) {
ys.add(originY + r * (labelH + rowGap));
ys.add(originY + r * (labelH + rowGap) + labelH);
}
return {
xs: [...xs].sort((a, b) => a - b),
ys: [...ys].sort((a, b) => a - b),
gridW,
gridH,
};
}
/** 间距为 0 且启用裁切线时,为裁切线预留半线宽通道,避免与标签图重叠导致内外粗细不一 */
export function getCutLineChannel(
columnGap: number,
rowGap: number,
cutLine: { enabled: boolean; width: number }
): { x: number; y: number } {
if (!cutLine.enabled) return { x: 0, y: 0 };
const half = cutLine.width / 2;
return {
x: columnGap === 0 ? half : 0,
y: rowGap === 0 ? half : 0,
};
}
export interface PrintableLabel {
row: RecordRow;
/** 原始数据行索引0-based用于变量解析 */