From 47672c5a9d756ce28d998d7f9f51abb8abc50d42 Mon Sep 17 00:00:00 2001 From: Robert Clarke Date: Thu, 12 Feb 2026 12:14:13 +0000 Subject: [PATCH] fix vertical description spacing (#797) --- .../trail/[handle]/[id]/print/+page.svelte | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/routes/map/trail/[handle]/[id]/print/+page.svelte b/web/src/routes/map/trail/[handle]/[id]/print/+page.svelte index d4b05b11..5e12e58c 100644 --- a/web/src/routes/map/trail/[handle]/[id]/print/+page.svelte +++ b/web/src/routes/map/trail/[handle]/[id]/print/+page.svelte @@ -110,7 +110,19 @@ } function getTextHeight(text: string, doc: jsPDF, width: number) { - let numLines = doc.splitTextToSize(text, width).length; + // Split text by newlines first to preserve blank lines + const paragraphs = text.split('\n'); + let numLines = 0; + + for (const paragraph of paragraphs) { + if (paragraph === '') { + // Empty line (blank line between paragraphs) + numLines += 1; + } else { + // Non-empty paragraph - count wrapped lines + numLines += doc.splitTextToSize(paragraph, width).length; + } + } return ( (numLines * doc.getFontSize() * doc.getLineHeightFactor() - @@ -382,8 +394,9 @@ } if (includeDescription && $trail.description) { + const descriptionText = formatHTMLAsText($trail.description); let textHeight = getTextHeight( - $trail.description, + descriptionText, doc, width - 32, ); @@ -391,15 +404,14 @@ newPage(); } doc.text( - formatHTMLAsText($trail.description), + descriptionText, 16, currentHeight, { maxWidth: width - 32, }, ); - currentHeight += - getTextHeight($trail.description, doc, width - 32) + 8; + currentHeight += textHeight + 8; } if (includeWaypoints && $trail.expand?.waypoints_via_trail) {