From f9420cb35066588b4643c0615d66e503bd7b60c0 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 02:41:24 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/forms/custom-form-builder.tsx | 43 +++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/components/forms/custom-form-builder.tsx b/src/components/forms/custom-form-builder.tsx index 418708e..46666ae 100644 --- a/src/components/forms/custom-form-builder.tsx +++ b/src/components/forms/custom-form-builder.tsx @@ -603,15 +603,46 @@ export function CustomFormBuilder() { let x = startX; if (align === "center") x = startX + (widthLimit - lineW) / 2; else if (align === "right") x = startX + (widthLimit - lineW); - for (const t of ln) { + // First pass: draw text. Track contiguous underline spans (incl. spaces between underlined tokens). + type Span = { x: number; w: number }; + const underlineSpans: Span[] = []; + let spanStart: number | null = null; + let spanWidth = 0; + const flushSpan = () => { + if (spanStart !== null && spanWidth > 0) { + underlineSpans.push({ x: spanStart, w: spanWidth }); + } + spanStart = null; + spanWidth = 0; + }; + for (let i = 0; i < ln.length; i++) { + const t = ln[i]; + const w = widthOf(t); doc.setFont(pdfFont, styleFor(t)); doc.text(t.text, x, yy); - if (t.underline && !t.isSpace) { - const w = widthOf(t); - doc.setLineWidth(0.5); - doc.line(x, yy + 1.5, x + w, yy + 1.5); + if (t.underline) { + // For a space, only continue an existing span if the next non-space token is also underlined. + if (t.isSpace) { + const next = ln[i + 1]; + if (spanStart !== null && next && next.underline) { + spanWidth += w; + } else { + flushSpan(); + } + } else { + if (spanStart === null) spanStart = x; + spanWidth += w; + } + } else { + flushSpan(); } - x += widthOf(t); + x += w; + } + flushSpan(); + // Second pass: draw underlines as continuous lines. + if (underlineSpans.length) { + doc.setLineWidth(0.5); + for (const s of underlineSpans) doc.line(s.x, yy + 1.5, s.x + s.w, yy + 1.5); } yy += lineH; }