Skip to content

Commit 5946a92

Browse files
committed
Add autoColorDark, autoColorLight options
+ Add `autoColorDark`, `autoColorLight` options # Optimize codes
1 parent 26aa1c9 commit 5946a92

File tree

5 files changed

+70
-42
lines changed

5 files changed

+70
-42
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ typings/
6060
# next.js build output
6161
.next
6262

63-
# temp
63+
# temp
64+
65+
# Test
66+
test

QRCode.js

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* React Native QRCode generation component. Can generate standard QRCode image or base64 image data url text. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.
55
*
6-
* Version 3.8.0
6+
* Version 3.9.0
77
*
88
* @author [ [email protected] ]
99
*
@@ -1085,11 +1085,11 @@ Drawing.prototype.draw = function(oQRCode) {
10851085

10861086
this._htOption.width = nWidth * nCount;
10871087
this._htOption.height = nHeight * nCount + _htOption.titleHeight;
1088-
this._canvas.height = his._htOption.height + this._htOption.quietZone * 2;
1088+
this._canvas.height = this._htOption.height + this._htOption.quietZone * 2;
10891089
this._canvas.width = this._htOption.width + this._htOption.quietZone * 2;
10901090

1091-
var autoColorDark = "rgba(0, 0, 0, .6)";
1092-
var autoColorLight = "rgba(255, 255, 255, .7)";
1091+
var autoColorDark = _htOption.autoColorDark;
1092+
var autoColorLight = _htOption.autoColorLight;
10931093
var notAutoColorLight = "rgba(0,0,0,0)";
10941094

10951095
this._oContext = this._canvas.getContext("2d");
@@ -1162,6 +1162,53 @@ Drawing.prototype.draw = function(oQRCode) {
11621162
var eye = oQRCode.getEye(row, col); // { isDark: true/false, type: PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL };
11631163

11641164
var nowDotScale = _htOption.dotScale;
1165+
1166+
_oContext.lineWidth = 0;
1167+
1168+
// Color handler
1169+
var dColor;
1170+
var lColor;
1171+
if (eye) {
1172+
dColor = _htOption[eye.type] || _htOption[eye.type.substring(
1173+
0, 2)] ||
1174+
_htOption.colorDark;
1175+
lColor = _htOption.colorLight;
1176+
} else {
1177+
if (_htOption.backgroundImage) {
1178+
1179+
lColor = "rgba(0,0,0,0)";
1180+
if (row == 6) {
1181+
dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark;
1182+
} else if (col == 6) {
1183+
dColor = _htOption.timing_V || _htOption.timing ||
1184+
_htOption.colorDark;
1185+
} else {
1186+
1187+
if (_htOption.autoColor) {
1188+
dColor = _htOption.autoColorDark;
1189+
lColor = _htOption.autoColorLight;
1190+
} else {
1191+
dColor = _htOption.colorDark;
1192+
}
1193+
}
1194+
1195+
} else {
1196+
if (row == 6) {
1197+
dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark;
1198+
} else if (col == 6) {
1199+
dColor = _htOption.timing_V || _htOption.timing ||
1200+
_htOption.colorDark;
1201+
} else {
1202+
dColor = _htOption.colorDark;
1203+
}
1204+
lColor = _htOption.colorLight;
1205+
}
1206+
}
1207+
_oContext.strokeStyle = bIsDark ? dColor :
1208+
lColor;
1209+
_oContext.fillStyle = bIsDark ? dColor :
1210+
lColor;
1211+
11651212
if (eye) {
11661213
// Is eye
11671214
bIsDark = eye.isDarkBlock;
@@ -1174,40 +1221,12 @@ Drawing.prototype.draw = function(oQRCode) {
11741221
nowDotScale = 1;
11751222
}
11761223

1177-
1178-
1179-
// PX_XX, PX, colorDark, colorLight
1180-
var eyeColorDark = _htOption[type] || _htOption[type.substring(0, 2)] || _htOption.colorDark;
1181-
1182-
_oContext.lineWidth = 0;
1183-
_oContext.strokeStyle = bIsDark ? eyeColorDark : _htOption.colorLight;
1184-
_oContext.fillStyle = bIsDark ? eyeColorDark : _htOption.colorLight;
1185-
11861224
// _oContext.fillRect(nLeft, _htOption.titleHeight + nTop, nWidth, nHeight);
11871225
_oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight +
11881226
nTop + nHeight * (1 -
11891227
nowDotScale) / 2, nWidth * nowDotScale, nHeight *
11901228
nowDotScale);
11911229
} else {
1192-
_oContext.lineWidth = 0;
1193-
_oContext.strokeStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
1194-
_oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
1195-
1196-
if (_htOption.backgroundImage) {
1197-
1198-
if (_htOption.autoColor) {
1199-
_oContext.strokeStyle = bIsDark ? autoColorDark : autoColorLight;
1200-
_oContext.fillStyle = bIsDark ? autoColorDark : autoColorLight;
1201-
} else {
1202-
_oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
1203-
_oContext.strokeStyle = _oContext.fillStyle;
1204-
}
1205-
1206-
} else {
1207-
_oContext.strokeStyle = _oContext.fillStyle;
1208-
1209-
1210-
}
12111230
if (row == 6) {
12121231
// Timing Pattern
12131232
nowDotScale = _htOption.dotScaleTiming_H;
@@ -1436,7 +1455,9 @@ function QRCode(canvas, vOption) {
14361455
// ==== Backgroud Image
14371456
backgroundImage: undefined, // Background Image
14381457
backgroundImageAlpha: 1, // Background image transparency, value between 0 and 1. default is 1.
1439-
autoColor: false,
1458+
autoColor: false, // Automatic color adjustment(for data block)
1459+
autoColorDark: "rgba(0, 0, 0, .6)", // Automatic color: dark CSS color
1460+
autoColorLight: "rgba(255, 255, 255, .7)", // Automatic color: light CSS color
14401461

14411462
// ==== Event Handler
14421463
onRenderingStart: undefined,
@@ -1551,7 +1572,7 @@ function QRCode(canvas, vOption) {
15511572

15521573

15531574
QRCode.prototype._show = function() {
1554-
var _oDrawing = new Drawing(this.canvas, this._htOption);
1575+
var _oDrawing = new Drawing(this.canvas, Object.assign({}, this._htOption));
15551576
this._oDrawing = _oDrawing;
15561577
_oDrawing.draw(this._oQRCode);
15571578
};

QRCode.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easyqrcode-react-native",
3-
"version": "3.8.0",
3+
"version": "3.9.0",
44
"description": "React Native QRCode generation component. Can get standard base64 image data url text or save image to file. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.",
55
"main": "QRCode.min.js",
66
"scripts": {},

readme.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ var qrcode = new QRCode(canvas_object, options_object);
158158
colorLight : "#ffffff",
159159
correctLevel : QRCode.CorrectLevel.H, // L, M, Q, H
160160

161-
// ====== dotScale
162-
/*
161+
// ====== dotScale
162+
/*
163163
dotScale: 1, // For body block, must be greater than 0, less than or equal to 1. default is 1
164164
165165
dotScaleTiming: 1, // Dafault for timing block , must be greater than 0, less than or equal to 1. default is 1
@@ -190,7 +190,9 @@ var qrcode = new QRCode(canvas_object, options_object);
190190
/*
191191
backgroundImage: '', // support: Static Image Resources, Network Images, Base64 Uri Data Images
192192
backgroundImageAlpha: 1, // Background image transparency, value between 0 and 1. default is 1.
193-
autoColor: false,
193+
autoColor: false, // Automatic color adjustment(for data block)
194+
autoColorDark: "rgba(0, 0, 0, .6)", // Automatic color: dark CSS color
195+
autoColorLight: "rgba(255, 255, 255, .7)", // Automatic color: light CSS color
194196
*/
195197

196198
// ====== Colorful
@@ -283,7 +285,9 @@ var qrcode = new QRCode(canvas_object, options_object);
283285
| Backgroud Image options| ---|--- |---|---|
284286
| **backgroundImage** | N | String | `undefined` | Background Image Path or Base64 encoded Image. If use relative address, relative to `easy.qrcode.min.js` |
285287
| **backgroundImageAlpha** | N | Number | `1.0` | Background image transparency. Ranges: `0-1.0` |
286-
| **autoColor** | N | Boolean | `false` | Automatic color adjustment |
288+
| **autoColor** | N | Boolean | `false` | Automatic color adjustment(for data block) |
289+
| **autoColorDark** | N | String | `rgba(0, 0, 0, .6)` | Automatic color: dark CSS color |
290+
| **autoColorLight** | N | String | `rgba(255, 255, 255, .7)` | Automatic color: light CSS color |
287291
| Posotion Pattern Color options| --- | ---|---|---|
288292
| **PO** | N | String | `undefined` | Global Posotion Outer CSS color. if not set, the defaut is `colorDark` |
289293
| **PI** | N | String | `undefined` | Global Posotion Inner CSS color. if not set, the defaut is `colorDark` |

0 commit comments

Comments
 (0)