|
3 | 3 | *
|
4 | 4 | * NodeJS QRCode generator. Can save image or svg to file, get standard base64 image data url text or get SVG serialized text. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.(Running without DOM on server side)
|
5 | 5 | *
|
6 |
| - * Version 4.4.0 |
| 6 | + * Version 4.4.1 |
7 | 7 | *
|
8 | 8 |
|
9 | 9 | *
|
@@ -35,7 +35,7 @@ const {
|
35 | 35 | } = jsdom;
|
36 | 36 | const win = new JSDOM().window;
|
37 | 37 |
|
38 |
| -function QR8bitByte(data, binary) { |
| 38 | +function QR8bitByte(data, binary, utf8WithoutBOM) { |
39 | 39 | this.mode = QRMode.MODE_8BIT_BYTE;
|
40 | 40 | this.data = data;
|
41 | 41 | this.parsedData = [];
|
@@ -70,7 +70,7 @@ function QR8bitByte(data, binary) {
|
70 | 70 |
|
71 | 71 | this.parsedData = Array.prototype.concat.apply([], this.parsedData);
|
72 | 72 |
|
73 |
| - if (this.parsedData.length != this.data.length) { |
| 73 | + if (!utf8WithoutBOM && this.parsedData.length != this.data.length) { |
74 | 74 | this.parsedData.unshift(191);
|
75 | 75 | this.parsedData.unshift(187);
|
76 | 76 | this.parsedData.unshift(239);
|
@@ -98,8 +98,8 @@ function QRCodeModel(typeNumber, errorCorrectLevel) {
|
98 | 98 | }
|
99 | 99 |
|
100 | 100 | QRCodeModel.prototype = {
|
101 |
| - addData: function(data, binary) { |
102 |
| - var newData = new QR8bitByte(data, binary); |
| 101 | + addData: function(data, binary, utf8WithoutBOM) { |
| 102 | + var newData = new QR8bitByte(data, binary, utf8WithoutBOM); |
103 | 103 | this.dataList.push(newData);
|
104 | 104 | this.dataCache = null;
|
105 | 105 | },
|
@@ -1461,7 +1461,7 @@ Drawing.prototype.draw = function(oQRCode) {
|
1461 | 1461 | // console.error(e);
|
1462 | 1462 | t.reject(e);
|
1463 | 1463 | }
|
1464 |
| - img.originalSrc=_htOption.logo; |
| 1464 | + img.originalSrc = _htOption.logo; |
1465 | 1465 | img.src = _htOption.logo;
|
1466 | 1466 | // if (img.complete) {
|
1467 | 1467 | // img.onload = null;
|
@@ -1548,14 +1548,14 @@ Drawing.prototype.makeImage = function() {
|
1548 | 1548 | if (this._htOption.onRenderingStart) {
|
1549 | 1549 | this._htOption.onRenderingStart(this._htOption);
|
1550 | 1550 | }
|
1551 |
| - |
| 1551 | + |
1552 | 1552 | if (this._htOption.format == 'PNG') {
|
1553 | 1553 | // dataUrl = this._canvas.toDataURL()
|
1554 | 1554 | t.resolve(this._canvas.createPNGStream());
|
1555 | 1555 | } else {
|
1556 | 1556 | t.resolve(this._canvas.createJPEGStream());
|
1557 | 1557 | }
|
1558 |
| - |
| 1558 | + |
1559 | 1559 | }
|
1560 | 1560 | };
|
1561 | 1561 |
|
@@ -1660,7 +1660,10 @@ function QRCode(vOption) {
|
1660 | 1660 | version: 0, // The symbol versions of QR Code range from Version 1 to Version 40. default 0 means automatically choose the closest version based on the text length.
|
1661 | 1661 |
|
1662 | 1662 | // ==== binary(hex) data mode
|
1663 |
| - binary: false // Whether it is binary mode, default is text mode. |
| 1663 | + binary: false, // Whether it is binary mode, default is text mode. |
| 1664 | + |
| 1665 | + // UTF-8 without BOM |
| 1666 | + utf8WithoutBOM: true |
1664 | 1667 | };
|
1665 | 1668 | if (typeof vOption === 'string') {
|
1666 | 1669 | vOption = {
|
@@ -1776,7 +1779,7 @@ function QRCode(vOption) {
|
1776 | 1779 |
|
1777 | 1780 | this._oQRCode = null;
|
1778 | 1781 | this._oQRCode = new QRCodeModel(_getTypeNumber(this._htOption.text, this._htOption), this._htOption.correctLevel);
|
1779 |
| - this._oQRCode.addData(this._htOption.text, this._htOption.binary); |
| 1782 | + this._oQRCode.addData(this._htOption.text, this._htOption.binary, this._htOption.utf8WithoutBOM); |
1780 | 1783 | this._oQRCode.make();
|
1781 | 1784 | }
|
1782 | 1785 |
|
@@ -1828,7 +1831,7 @@ QRCode.prototype.saveSVG = function(saveOptions) {
|
1828 | 1831 | // Get Base64 or SVG text
|
1829 | 1832 | QRCode.prototype._toData = function(drawer, makeType) {
|
1830 | 1833 | var defOptions = {
|
1831 |
| - makeType: makeType?makeType:'URL' |
| 1834 | + makeType: makeType ? makeType : 'URL' |
1832 | 1835 | }
|
1833 | 1836 | this._htOption._drawer = drawer;
|
1834 | 1837 |
|
|
0 commit comments