Skip to content

Commit cda5694

Browse files
fix passing lineHeightFactor to the text method (#3283)
Co-authored-by: Lukas Holländer <[email protected]>
1 parent 57d6fb2 commit cda5694

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/jspdf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3616,7 +3616,8 @@ function jsPDF(options) {
36163616

36173617
//baseline
36183618
var height = activeFontSize / scope.internal.scaleFactor;
3619-
var descent = height * (lineHeightFactor - 1);
3619+
var descent = height * (lineHeight - 1);
3620+
36203621
switch (options.baseline) {
36213622
case "bottom":
36223623
y -= descent;

test/specs/jspdf.unit.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,21 @@ This is a test too.`,
25232523
]);
25242524
});
25252525

2526+
it('jsPDF test text with line height', function() {
2527+
const doc1 = new jsPDF();
2528+
let writeArray1 = [];
2529+
doc1.__private__.setCustomOutputDestination(writeArray1);
2530+
doc1.setLineHeightFactor(1.5);
2531+
doc1.text('Some text', 10, 10, { baseline: 'middle' });
2532+
2533+
let writeArray2 = [];
2534+
const doc2 = new jsPDF();
2535+
doc2.__private__.setCustomOutputDestination(writeArray2);
2536+
doc2.text('Some text', 10, 10, { lineHeightFactor: 1.5, baseline: 'middle' });
2537+
2538+
expect(writeArray1).toEqual(writeArray2);
2539+
});
2540+
25262541
it("jsPDF private function setLineCap", () => {
25272542
var doc = jsPDF({ floatPrecision: 2 });
25282543

0 commit comments

Comments
 (0)