Skip to content

Commit 102f370

Browse files
authored
Merge pull request #3062 from HackbrettXXX/fix-text-encoding-flags
fix text encoding flags
2 parents edab14a + b686db7 commit 102f370

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/jspdf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3777,7 +3777,8 @@ function jsPDF(options) {
37773777
maxWidth = options.maxWidth || 0;
37783778

37793779
var lineWidths;
3780-
flags = {};
3780+
flags = Object.assign({ autoencode: true, noBOM: true }, options.flags);
3781+
37813782
var wordSpacingPerLine = [];
37823783

37833784
if (Object.prototype.toString.call(text) === "[object Array]") {
3.46 KB
Binary file not shown.

test/specs/text.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,24 @@ break`
210210
doc.text("hello", 10, 40, { charSpace: 10 });
211211
comparePdf(doc.output(), "letter-spacing.pdf", "text");
212212
});
213+
214+
it("should respect autoencode and noBOM flags", () => {
215+
const doc = jsPDF({ floatPrecision: 2 });
216+
217+
doc.text("Default:", 10, 10);
218+
doc.text("é'\"´`'\u2019", 150, 10);
219+
220+
doc.text("autoencode=false:", 10, 30);
221+
doc.text("é'\"´`'\u2019", 150, 30, { flags: { autoencode: false } });
222+
223+
doc.text("noBOM=false:", 10, 60);
224+
doc.text("é'\"´`'\u2019", 150, 60, { flags: { noBOM: false } });
225+
226+
doc.text("noBOM=false,autoencode=false (garbled):", 10, 90);
227+
doc.text("é'\"´`'\u2019", 150, 90, {
228+
flags: { autoencode: false, noBOM: false }
229+
});
230+
231+
comparePdf(doc.output(), "text-encoding-flags.pdf", "text");
232+
});
213233
});

0 commit comments

Comments
 (0)