From b686db770f55910ad1c4982b9a09e51f041a7e71 Mon Sep 17 00:00:00 2001 From: Lukas Hollaender Date: Fri, 15 Jan 2021 15:03:36 +0100 Subject: [PATCH] fix text encoding flags --- src/jspdf.js | 3 ++- test/reference/text-encoding-flags.pdf | Bin 0 -> 3539 bytes test/specs/text.spec.js | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/reference/text-encoding-flags.pdf diff --git a/src/jspdf.js b/src/jspdf.js index 5c73920ed..39b25569c 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -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]") { diff --git a/test/reference/text-encoding-flags.pdf b/test/reference/text-encoding-flags.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c7fb6a2ef8847c3d3cee16b0e4929495727ca911 GIT binary patch literal 3539 zcmcInQE%c#5axORLElCvMI>rtdl%L=CmQL1(2Fi7B7)Saxsz^zg>z)=)L!2u_cQuC z`gl+MGwtjBiQdf^(>Nw6qzZuWc$nFl{rv6Buy@w$A9Aa~_Wu0qkH1+19Eiu4tlhRp zH&+_$Gd0%?zY`r9;P~s1*+ZSiSu)Wnh^6ASo(8HDU&Doi3fYpD@WF3#%Wu79b~la; zdZ*CLt&fhFj;0iZ?w7%seX66mc@MH77#gG|(Q3gQOM38;Iq(zfjF{c$z+D*4827Cv zj85@~ITOCskl^!%B~dqJ`#n8VS!kXg!03`4j~@1H3e2*)ms-8{toFI~u2zTdwoJkG5MrLE5XGIr>&Hbec|UIF z(swP-tA_odiUPdZpQ~gX>gk(vB^&aoeR$FV|v~}Gza_VAbJs{ z!AgNV4U*J!->U?W&GxA(ZiJMj;O_Rp4?A%ClTi$yQc$X*eZ!U_<@Fzxv!DI*f-&`1P_rJ3wHrK{q)zz$r^?$4k z_L^#0+^Ple&BgEhW-*S#|G9qoM4ct^L$+c0SqGDjl*mamEv3{dWMs&;H=06FW^dvQ|=5_I?q8! z=mpVAC!|0q@9G?fAg$>5J$9bE?(6%A<6U3w5VjQ^mq@gVPTb?$BnDLMWD`NF=v)u! zQPKI%dfZlH9Rp{5AA+~m))NhZ^tu~EH1SVMRp)tYISXHw>`bD95QhRfEa$-|P0!69 v#<78%FUa?kXcj|GNxJF51+?=h|M7LSjmcZ$OlnkOa>j_3E7;!N@u2?=Wthi_ literal 0 HcmV?d00001 diff --git a/test/specs/text.spec.js b/test/specs/text.spec.js index 34e6b5bfa..f5044db01 100644 --- a/test/specs/text.spec.js +++ b/test/specs/text.spec.js @@ -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"); + }); });