fix vertical description spacing (#797)

This commit is contained in:
Robert Clarke
2026-02-12 12:14:13 +00:00
committed by GitHub
parent 721c84c1d8
commit 47672c5a9d

View File

@@ -110,7 +110,19 @@
} }
function getTextHeight(text: string, doc: jsPDF, width: number) { 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 ( return (
(numLines * doc.getFontSize() * doc.getLineHeightFactor() - (numLines * doc.getFontSize() * doc.getLineHeightFactor() -
@@ -382,8 +394,9 @@
} }
if (includeDescription && $trail.description) { if (includeDescription && $trail.description) {
const descriptionText = formatHTMLAsText($trail.description);
let textHeight = getTextHeight( let textHeight = getTextHeight(
$trail.description, descriptionText,
doc, doc,
width - 32, width - 32,
); );
@@ -391,15 +404,14 @@
newPage(); newPage();
} }
doc.text( doc.text(
formatHTMLAsText($trail.description), descriptionText,
16, 16,
currentHeight, currentHeight,
{ {
maxWidth: width - 32, maxWidth: width - 32,
}, },
); );
currentHeight += currentHeight += textHeight + 8;
getTextHeight($trail.description, doc, width - 32) + 8;
} }
if (includeWaypoints && $trail.expand?.waypoints_via_trail) { if (includeWaypoints && $trail.expand?.waypoints_via_trail) {