From a08fbd1eb6583808a75d97aa8e5c1b5e1f281263 Mon Sep 17 00:00:00 2001 From: iqudoo Date: Sat, 13 Jun 2026 05:51:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PreviewGrid.tsx | 13 +++++-------- src/pdfExport.ts | 8 ++++---- src/utils.ts | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/components/PreviewGrid.tsx b/src/components/PreviewGrid.tsx index 32bc33f..b6c9ce6 100644 --- a/src/components/PreviewGrid.tsx +++ b/src/components/PreviewGrid.tsx @@ -8,6 +8,8 @@ import { buildPrintablePages, collectGridCutLinePositions, getCutLineChannel, + formatCutLineSvgDashArray, + getCutLineStrokeWidthMm, loadAutoLayoutMinPageMarginMm, saveAutoLayoutMinPageMarginMm, type PrintableLabel, @@ -578,15 +580,12 @@ export const LayoutPreview: React.FC = ({ const rowGapPx = Math.max(0, paper.rowGap * previewScale); const labelWPx = template.width * previewScale; const labelHPx = template.height * previewScale; - const cutStrokeWidth = Math.max(0.5, cutLine.width * previewScale); + const cutStrokeWidth = getCutLineStrokeWidthMm(cutLine) * previewScale; const cutHalfStroke = cutStrokeWidth / 2; const cutChannel = getCutLineChannel(paper.columnGap, paper.rowGap, cutLine); const cutChannelXPx = cutChannel.x * previewScale; const cutChannelYPx = cutChannel.y * previewScale; - const cutDash = - cutLine.style === 'dashed' - ? `${Math.max(2, cutStrokeWidth * 4)} ${Math.max(2, cutStrokeWidth * 4)}` - : undefined; + const cutDash = formatCutLineSvgDashArray(cutLine, previewScale); const pageCutLines = useMemo( () => collectGridCutLinePositions( @@ -770,7 +769,6 @@ export const LayoutPreview: React.FC = ({ strokeWidth={cutStrokeWidth} strokeDasharray={cutDash} strokeLinecap="butt" - shapeRendering="crispEdges" /> ))} {pageCutLines.xs.map((x) => ( @@ -784,7 +782,6 @@ export const LayoutPreview: React.FC = ({ strokeWidth={cutStrokeWidth} strokeDasharray={cutDash} strokeLinecap="butt" - shapeRendering="crispEdges" /> ))} @@ -794,7 +791,7 @@ export const LayoutPreview: React.FC = ({ return (
): number { + return Math.max(0.02, cutLine.width); +} + +/** 虚线单段长度 (mm),预览与 PDF 共用 */ +export function getCutLineDashSegmentMm(cutLine: Pick): number { + if (cutLine.style !== 'dashed') return 0; + return Math.max(0.5, cutLine.width * 4); +} + +/** 预览 SVG strokeDasharray,scale 为 mm→px 比例 */ +export function formatCutLineSvgDashArray( + cutLine: Pick, + scale: number +): string | undefined { + if (cutLine.style !== 'dashed') return undefined; + const seg = getCutLineDashSegmentMm(cutLine) * scale; + return `${seg} ${seg}`; +} + export interface GridCutLinePositions { xs: number[]; ys: number[];