Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTextDimensions should automatically infer numberOfLines if maxTextWidth is provided #2824

Merged
merged 7 commits into from Aug 10, 2020
1 change: 1 addition & 0 deletions spec/cell.spec.js
Expand Up @@ -19,6 +19,7 @@ describe("Module: Cell", () => {
144.48000000000002
);
expect(doc.getTextDimensions("Octocat loves jsPDF").h).toEqual(16);
expect(doc.getTextDimensions("Octocat loves jsPDF", {maxWidth: 100 }).h).toEqual(34.4);
expect(doc.getTextDimensions("").w).toEqual(0);
expect(doc.getTextDimensions("").h).toEqual(0);
expect(doc.getTextDimensions([""]).w).toEqual(0);
Expand Down
10 changes: 7 additions & 3 deletions src/modules/cell.js
Expand Up @@ -198,9 +198,13 @@
if (width < tempWidth) {
width = tempWidth;
}
if (width !== 0) {
amountOfLines = text.length;
}
}

if (options.maxWidth){
amountOfLines = this.splitTextToSize(text, options.maxWidth)
Nnoerregaard marked this conversation as resolved.
Show resolved Hide resolved
}
else if (width !== 0) {
amountOfLines = text.length;
}

width = width / scaleFactor;
Expand Down