Skip to content

Commit

Permalink
Merge pull request #3062 from HackbrettXXX/fix-text-encoding-flags
Browse files Browse the repository at this point in the history
fix text encoding flags
  • Loading branch information
HackbrettXXX committed Jan 15, 2021
2 parents edab14a + b686db7 commit 102f370
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jspdf.js
Expand Up @@ -3777,7 +3777,8 @@ function jsPDF(options) {
maxWidth = options.maxWidth || 0;

var lineWidths;
flags = {};
flags = Object.assign({ autoencode: true, noBOM: true }, options.flags);

var wordSpacingPerLine = [];

if (Object.prototype.toString.call(text) === "[object Array]") {
Expand Down
Binary file added test/reference/text-encoding-flags.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions test/specs/text.spec.js
Expand Up @@ -210,4 +210,24 @@ break`
doc.text("hello", 10, 40, { charSpace: 10 });
comparePdf(doc.output(), "letter-spacing.pdf", "text");
});

it("should respect autoencode and noBOM flags", () => {
const doc = jsPDF({ floatPrecision: 2 });

doc.text("Default:", 10, 10);
doc.text("é'\"´`'\u2019", 150, 10);

doc.text("autoencode=false:", 10, 30);
doc.text("é'\"´`'\u2019", 150, 30, { flags: { autoencode: false } });

doc.text("noBOM=false:", 10, 60);
doc.text("é'\"´`'\u2019", 150, 60, { flags: { noBOM: false } });

doc.text("noBOM=false,autoencode=false (garbled):", 10, 90);
doc.text("é'\"´`'\u2019", 150, 90, {
flags: { autoencode: false, noBOM: false }
});

comparePdf(doc.output(), "text-encoding-flags.pdf", "text");
});
});

0 comments on commit 102f370

Please sign in to comment.