Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 02:41:24 +00:00
co-authored by renee-png
parent 2cde2c246d
commit f9420cb350
+37 -6
View File
@@ -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;
}