From f548962b192143afc3aca97553e40648a2bfc998 Mon Sep 17 00:00:00 2001 From: alxndr-pggm Date: Mon, 18 Aug 2025 08:49:37 +0200 Subject: [PATCH 1/2] Fix division by zero when calculating word spacing --- src/jspdf.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jspdf.js b/src/jspdf.js index dc009f313..14dce6095 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -3907,11 +3907,15 @@ function jsPDF(options) { for (var l = 0; l < len; l++) { newY = l === 0 ? getVerticalCoordinate(y) : -leading; newX = l === 0 ? getHorizontalCoordinate(x) : 0; + + let numSpaces = da[l].split(" ").length - 1; + let spacing = numSpaces > 0 ? (maxWidth - lineWidths[l]) / numSpaces : 0; + if (l < len - 1) { wordSpacingPerLine.push( hpf( scale( - (maxWidth - lineWidths[l]) / (da[l].split(" ").length - 1) + (spacing) ) ) ); From db723d51d0b02692d12a5ffa79ae904fd55603dd Mon Sep 17 00:00:00 2001 From: alxndr-pggm Date: Fri, 29 Aug 2025 10:49:25 +0000 Subject: [PATCH 2/2] fix linting errors --- src/jspdf.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/jspdf.js b/src/jspdf.js index 14dce6095..ac63154c5 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -3908,17 +3908,12 @@ function jsPDF(options) { newY = l === 0 ? getVerticalCoordinate(y) : -leading; newX = l === 0 ? getHorizontalCoordinate(x) : 0; - let numSpaces = da[l].split(" ").length - 1; - let spacing = numSpaces > 0 ? (maxWidth - lineWidths[l]) / numSpaces : 0; + const numSpaces = da[l].split(" ").length - 1; + const spacing = + numSpaces > 0 ? (maxWidth - lineWidths[l]) / numSpaces : 0; if (l < len - 1) { - wordSpacingPerLine.push( - hpf( - scale( - (spacing) - ) - ) - ); + wordSpacingPerLine.push(hpf(scale(spacing))); } else { wordSpacingPerLine.push(0); }