Skip to content

Commit c44df88

Browse files
committed
fix lineHeightFactor bug
refs: parallax#3234
1 parent 30880b4 commit c44df88

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/jspdf.js

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

36133613
//baseline
36143614
var height = activeFontSize / scope.internal.scaleFactor;
3615-
var descent = height * (lineHeightFactor - 1);
3615+
var descent;
3616+
if (
3617+
options.lineHeightFactor &&
3618+
typeof options.lineHeightFactor === "number"
3619+
)
3620+
descent = height * (options.lineHeightFactor - 1);
3621+
else descent = height * (lineHeightFactor - 1);
3622+
36163623
switch (options.baseline) {
36173624
case "bottom":
36183625
y -= descent;

test/reference/lineHeight.pdf

3.07 KB
Binary file not shown.

test/specs/lineHeight.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable no-self-assign */
2+
/* global describe, it, expect, jsPDF, comparePdf, Button, ComboBox, ChoiceField, EditBox, ListBox, PushButton, CheckBox, TextField, PasswordField, RadioButton, AcroForm */
3+
4+
/**
5+
* line height testing
6+
*/
7+
8+
describe("Module: Line Height Unit Test", function() {
9+
beforeAll(loadGlobals);
10+
it('test line height', function() {
11+
const doc1 = new jsPDF();
12+
doc1.setLineHeightFactor(1.5);
13+
doc1.text('Some text', 10, 10, { baseline: 'middle' });
14+
comparePdf(doc1.output(), 'lineHeight.pdf', 'lineHeight');
15+
16+
const doc2 = new jsPDF();
17+
doc2.text('Some text', 10, 10, { lineHeightFactor: 1.5, baseline: 'middle' });
18+
comparePdf(doc2.output(), 'lineHeight.pdf', 'lineHeight');
19+
});
20+
});

0 commit comments

Comments
 (0)