|
3 | 3 | * |
4 | 4 | * Cross-browser QRCode generator for pure javascript. Support Canvas, SVG and Table drawing methods. Support Dot style, Logo, Background image, Colorful, Title etc. settings. Support Angular, Vue.js, React, Next.js framework. Support binary(hex) data mode.(Running with DOM on client side) |
5 | 5 | * |
6 | | - * Version 4.2.1 |
| 6 | + * Version 4.3.0 |
7 | 7 | * |
8 | 8 | |
9 | 9 | * |
|
1301 | 1301 | if (this._htOption.onRenderingEnd) { |
1302 | 1302 | if (!this.dataURL) { |
1303 | 1303 | console.error( |
1304 | | - "Can not get base64 data, please check: 1. published the page and image to the server 2. The image request support CORS" |
| 1304 | + "Can not get base64 data, please check: 1. Published the page and image to the server 2. The image request support CORS 3. Configured `crossOrigin:'anonymous'` option" |
1305 | 1305 | ) |
1306 | 1306 | } |
1307 | 1307 | this._htOption.onRenderingEnd(this._htOption, this.dataURL); |
|
1508 | 1508 | var eye = oQRCode.getEye(row, col); // { isDark: true/false, type: PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL }; |
1509 | 1509 |
|
1510 | 1510 | var nowDotScale = _htOption.dotScale; |
| 1511 | + |
| 1512 | + _oContext.lineWidth = 0; |
| 1513 | + // Color handler |
| 1514 | + var dColor; |
| 1515 | + var lColor; |
| 1516 | + if (eye) { |
| 1517 | + dColor = _htOption[eye.type] || _htOption[eye.type.substring( |
| 1518 | + 0, 2)] || |
| 1519 | + _htOption.colorDark; |
| 1520 | + lColor = _htOption.colorLight; |
| 1521 | + } else { |
| 1522 | + if (_htOption.backgroundImage) { |
| 1523 | + |
| 1524 | + lColor = "rgba(0,0,0,0)"; |
| 1525 | + if (row == 6) { |
| 1526 | + dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark; |
| 1527 | + } else if (col == 6) { |
| 1528 | + dColor = _htOption.timing_V || _htOption.timing || |
| 1529 | + _htOption.colorDark; |
| 1530 | + } else { |
| 1531 | + |
| 1532 | + if (_htOption.autoColor) { |
| 1533 | + dColor = _htOption.autoColorDark; |
| 1534 | + lColor = _htOption.autoColorLight; |
| 1535 | + } else { |
| 1536 | + dColor = _htOption.colorDark; |
| 1537 | + } |
| 1538 | + } |
| 1539 | + |
| 1540 | + } else { |
| 1541 | + if (row == 6) { |
| 1542 | + dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark; |
| 1543 | + } else if (col == 6) { |
| 1544 | + dColor = _htOption.timing_V || _htOption.timing || |
| 1545 | + _htOption.colorDark; |
| 1546 | + } else { |
| 1547 | + dColor = _htOption.colorDark; |
| 1548 | + } |
| 1549 | + lColor = _htOption.colorLight; |
| 1550 | + } |
| 1551 | + } |
| 1552 | + _oContext.strokeStyle = bIsDark ? dColor : |
| 1553 | + lColor; |
| 1554 | + _oContext.fillStyle = bIsDark ? dColor : |
| 1555 | + lColor; |
| 1556 | + |
1511 | 1557 | if (eye) { |
1512 | 1558 | if (eye.type == 'AO') { |
1513 | 1559 | nowDotScale = _htOption.dotScaleAO; |
|
1519 | 1565 |
|
1520 | 1566 | // Is eye |
1521 | 1567 | bIsDark = eye.isDark; |
1522 | | - var type = eye.type; |
1523 | | - |
1524 | | - // PX_XX, PX, colorDark, colorLight |
1525 | | - var eyeColorDark = _htOption[type] || _htOption[type.substring(0, 2)] || |
1526 | | - _htOption.colorDark; |
1527 | | - |
1528 | | - _oContext.lineWidth = 0; |
1529 | | - _oContext.strokeStyle = bIsDark ? eyeColorDark : _htOption.colorLight; |
1530 | | - _oContext.fillStyle = bIsDark ? eyeColorDark : _htOption.colorLight; |
1531 | | - |
1532 | | - // _oContext.fillRect(nLeft, _htOption.titleHeight + nTop, nWidth, nHeight); |
1533 | 1568 |
|
1534 | 1569 |
|
1535 | 1570 | _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + |
|
1538 | 1573 | nowDotScale); |
1539 | 1574 |
|
1540 | 1575 | } else { |
1541 | | - _oContext.lineWidth = 0; |
1542 | | - _oContext.strokeStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight; |
1543 | | - _oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight; |
1544 | | - |
1545 | | - if (_htOption.backgroundImage) { |
1546 | | - |
1547 | | - if (_htOption.autoColor) { |
1548 | | - _oContext.strokeStyle = bIsDark ? "rgba(0, 0, 0, .6)" : |
1549 | | - "rgba(255, 255, 255, .7)"; |
1550 | | - _oContext.fillStyle = bIsDark ? "rgba(0, 0, 0, .6)" : |
1551 | | - "rgba(255, 255, 255, .7)"; |
1552 | | - } else { |
1553 | | - _oContext.strokeStyle = bIsDark ? _htOption.colorDark : |
1554 | | - "rgba(0,0,0,0)"; |
1555 | | - _oContext.fillStyle = bIsDark ? _htOption.colorDark : |
1556 | | - "rgba(0,0,0,0)"; |
1557 | | - _oContext.strokeStyle = _oContext.fillStyle; |
1558 | | - } |
1559 | | - |
1560 | | - } else { |
1561 | | - _oContext.strokeStyle = _oContext.fillStyle; |
1562 | | - |
1563 | | - |
1564 | | - } |
1565 | 1576 |
|
1566 | 1577 | if (row == 6) { |
1567 | 1578 | // Timing Pattern |
1568 | | - var timingHColorDark = _htOption.timing_H || _htOption.timing || |
1569 | | - _htOption.colorDark; |
1570 | | - _oContext.fillStyle = bIsDark ? timingHColorDark : _htOption.colorLight; |
1571 | | - _oContext.strokeStyle = _oContext.fillStyle; |
1572 | 1579 |
|
1573 | 1580 | nowDotScale = _htOption.dotScaleTiming_H; |
1574 | 1581 |
|
|
1578 | 1585 | nowDotScale); |
1579 | 1586 | } else if (col == 6) { |
1580 | 1587 | // Timing Pattern |
1581 | | - var timingVColorDark = _htOption.timing_V || _htOption.timing || |
1582 | | - _htOption.colorDark; |
1583 | | - _oContext.fillStyle = bIsDark ? timingVColorDark : _htOption.colorLight; |
1584 | | - _oContext.strokeStyle = _oContext.fillStyle; |
1585 | | - |
1586 | 1588 | nowDotScale = _htOption.dotScaleTiming_V; |
1587 | 1589 |
|
1588 | 1590 | _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + |
|
1891 | 1893 | // ==== Backgroud Image |
1892 | 1894 | backgroundImage: undefined, // Background Image |
1893 | 1895 | backgroundImageAlpha: 1, // Background image transparency, value between 0 and 1. default is 1. |
1894 | | - autoColor: false, |
| 1896 | + autoColor: false, // Automatic color adjustment(for data block) |
| 1897 | + autoColorDark: "rgba(0, 0, 0, .6)", // Automatic color: dark CSS color |
| 1898 | + autoColorLight: "rgba(255, 255, 255, .7)", // Automatic color: light CSS color |
1895 | 1899 |
|
1896 | 1900 | // ==== Event Handler |
1897 | 1901 | onRenderingStart: undefined, |
|
1909 | 1913 | // ==== Drawing method |
1910 | 1914 | drawer: 'canvas', // Drawing method: canvas, svg(Chrome, FF, IE9+) |
1911 | 1915 |
|
1912 | | - |
1913 | 1916 | // ==== CORS |
1914 | 1917 | crossOrigin: null // String which specifies the CORS setting to use when retrieving the image. null means that the crossOrigin attribute is not set. |
1915 | 1918 | }; |
|
2016 | 2019 | this._android = _getAndroid(); |
2017 | 2020 | this._el = el; |
2018 | 2021 | this._oQRCode = null; |
2019 | | - this._oDrawing = new Drawing(this._el, this._htOption); |
| 2022 | + |
| 2023 | + var _htOptionClone={}; |
| 2024 | + for(var i in this._htOption){ |
| 2025 | + _htOptionClone[i] = this._htOption[i]; |
| 2026 | + } |
| 2027 | + this._oDrawing = new Drawing(this._el, _htOptionClone); |
2020 | 2028 |
|
2021 | 2029 | if (this._htOption.text) { |
2022 | 2030 | this.makeCode(this._htOption.text); |
|
0 commit comments