Skip to content

Commit 064194f

Browse files
Fix division by zero when calculating word spacing (#3879)
Co-authored-by: Lukas Holländer <[email protected]>
1 parent 543b356 commit 064194f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/jspdf.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3907,14 +3907,13 @@ function jsPDF(options) {
39073907
for (var l = 0; l < len; l++) {
39083908
newY = l === 0 ? getVerticalCoordinate(y) : -leading;
39093909
newX = l === 0 ? getHorizontalCoordinate(x) : 0;
3910+
3911+
const numSpaces = da[l].split(" ").length - 1;
3912+
const spacing =
3913+
numSpaces > 0 ? (maxWidth - lineWidths[l]) / numSpaces : 0;
3914+
39103915
if (l < len - 1) {
3911-
wordSpacingPerLine.push(
3912-
hpf(
3913-
scale(
3914-
(maxWidth - lineWidths[l]) / (da[l].split(" ").length - 1)
3915-
)
3916-
)
3917-
);
3916+
wordSpacingPerLine.push(hpf(scale(spacing)));
39183917
} else {
39193918
wordSpacingPerLine.push(0);
39203919
}

0 commit comments

Comments
 (0)