Skip to content

Commit bfcca5f

Browse files
committed
Add dotSacale for Timing and Alignment
Add dotSacale for Timing and Alignment.
1 parent dfefd69 commit bfcca5f

File tree

4 files changed

+128
-32
lines changed

4 files changed

+128
-32
lines changed

index.js

Lines changed: 101 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* 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)
55
*
6-
* Version 4.0.0
6+
* Version 4.1.0
77
*
88
* @author [ [email protected] ]
99
*
@@ -1129,7 +1129,7 @@ Drawing.prototype.draw = function(oQRCode) {
11291129
// JPG
11301130
if (_htOption.format == 'JPG') {
11311131

1132-
if (_htOption.quietZoneColor == 'transparent') {
1132+
if (_htOption.quietZoneColor == "rgba(0,0,0,0)") {
11331133
_htOption.quietZoneColor = '#ffffff';
11341134
}
11351135

@@ -1196,61 +1196,70 @@ Drawing.prototype.draw = function(oQRCode) {
11961196

11971197
var eye = oQRCode.getEye(row, col); // { isDark: true/false, type: PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL };
11981198

1199+
var nowDotScale = _htOption.dotScale;
1200+
11991201
if (eye) {
12001202
// Is eye
12011203
bIsDark = eye.isDarkBlock;
12021204
var type = eye.type;
1205+
if (type == 'AO') {
1206+
nowDotScale = _htOption.dotScaleAO;
1207+
} else if (type == 'AI') {
1208+
nowDotScale = _htOption.dotScaleAI;
1209+
} else {
1210+
nowDotScale = 1;
1211+
}
12031212

12041213
// PX_XX, PX, colorDark, colorLight
12051214
var eyeColorDark = _htOption[type] || _htOption[type.substring(0, 2)] || _htOption.colorDark;
1206-
12071215
_oContext.lineWidth = 0;
12081216
_oContext.strokeStyle = bIsDark ? eyeColorDark : _htOption.colorLight;
12091217
_oContext.fillStyle = bIsDark ? eyeColorDark : _htOption.colorLight;
12101218

1211-
_oContext.fillRect(nLeft, _htOption.titleHeight + nTop, nWidth, nHeight);
1212-
1219+
_oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop + nHeight * (1 - nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
12131220
} else {
12141221
_oContext.lineWidth = 0;
12151222
_oContext.strokeStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
12161223
_oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
12171224

1218-
var nowDotScale = _htOption.dotScale;
1225+
if (_htOption.backgroundImage) {
1226+
1227+
if (_htOption.autoColor) {
1228+
_oContext.strokeStyle = bIsDark ? autoColorDark : autoColorLight;
1229+
_oContext.fillStyle = bIsDark ? autoColorDark : autoColorLight;
1230+
} else {
1231+
_oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
1232+
_oContext.strokeStyle = _oContext.fillStyle;
1233+
}
1234+
} else {
1235+
_oContext.strokeStyle = _oContext.fillStyle;
1236+
1237+
}
1238+
12191239
if (row == 6) {
12201240
// Timing Pattern
1221-
nowDotScale = 1;
1222-
var timingHColorDark = _htOption.timing_H || _htOption.timing || _htOption.colorDark;
1223-
_oContext.fillStyle = bIsDark ? timingHColorDark : _htOption.colorLight;
1224-
_oContext.strokeStyle = _oContext.fillStyle;
1241+
nowDotScale = _htOption.dotScaleTiming_H;
1242+
12251243
_oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop +
12261244
nHeight * (1 -
12271245
nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
12281246
} else if (col == 6) {
12291247
// Timing Pattern
1230-
nowDotScale = 1;
1231-
var timingVColorDark = _htOption.timing_V || _htOption.timing || _htOption.colorDark;
1232-
_oContext.fillStyle = bIsDark ? timingVColorDark : _htOption.colorLight;
1233-
_oContext.strokeStyle = _oContext.fillStyle;
1248+
nowDotScale = _htOption.dotScaleTiming_V;
1249+
12341250
_oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop +
12351251
nHeight * (1 -
12361252
nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
12371253
} else {
12381254

12391255
if (_htOption.backgroundImage) {
12401256

1241-
if (_htOption.autoColor) {
1242-
_oContext.strokeStyle = bIsDark ? autoColorDark : autoColorLight;
1243-
_oContext.fillStyle = bIsDark ? autoColorDark : autoColorLight;
1244-
} else {
1245-
_oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
1246-
_oContext.strokeStyle = _oContext.fillStyle;
1247-
}
12481257
_oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop +
12491258
nHeight * (1 -
12501259
nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
12511260

12521261
} else {
1253-
_oContext.strokeStyle = _oContext.fillStyle;
1262+
12541263

12551264
_oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop +
12561265
nHeight * (1 -
@@ -1470,10 +1479,18 @@ function QRCode(vOption) {
14701479
colorLight: "#ffffff",
14711480
correctLevel: QRErrorCorrectLevel.H,
14721481

1473-
dotScale: 1, // Must be greater than 0, less than or equal to 1. default is 1
1482+
dotScale: 1, // For body block, must be greater than 0, less than or equal to 1. default is 1
1483+
1484+
dotScaleTiming: 1, // Dafault for timing block , must be greater than 0, less than or equal to 1. default is 1
1485+
dotScaleTiming_H: undefined, // For horizontal timing block, must be greater than 0, less than or equal to 1. default is 1
1486+
dotScaleTiming_V: undefined, // For vertical timing block, must be greater than 0, less than or equal to 1. default is 1
1487+
1488+
dotScaleA: 1, // Dafault for alignment block, must be greater than 0, less than or equal to 1. default is 1
1489+
dotScaleAO: undefined, // For alignment outer block, must be greater than 0, less than or equal to 1. default is 1
1490+
dotScaleAI: undefined, // For alignment inner block, must be greater than 0, less than or equal to 1. default is 1
14741491

14751492
quietZone: 0,
1476-
quietZoneColor: 'transparent',
1493+
quietZoneColor: "rgba(0,0,0,0)",
14771494

14781495
title: "",
14791496
titleFont: "bold 16px Arial",
@@ -1570,6 +1587,66 @@ function QRCode(vOption) {
15701587
" , is invalidate, dotScale must greater than 0, less than or equal to 1, now reset to 1. ")
15711588
this._htOption.dotScale = 1;
15721589
}
1590+
1591+
if (this._htOption.dotScaleTiming < 0 || this._htOption.dotScaleTiming > 1) {
1592+
console.warn(this._htOption.dotScaleTiming +
1593+
" , is invalidate, dotScaleTiming must greater than 0, less than or equal to 1, now reset to 1. "
1594+
)
1595+
this._htOption.dotScaleTiming = 1;
1596+
}
1597+
if (this._htOption.dotScaleTiming_H) {
1598+
if (this._htOption.dotScaleTiming_H < 0 || this._htOption.dotScaleTiming_H > 1) {
1599+
console.warn(this._htOption.dotScaleTiming_H +
1600+
" , is invalidate, dotScaleTiming_H must greater than 0, less than or equal to 1, now reset to 1. "
1601+
)
1602+
this._htOption.dotScaleTiming_H = 1;
1603+
}
1604+
} else {
1605+
this._htOption.dotScaleTiming_H = this._htOption.dotScaleTiming;
1606+
}
1607+
1608+
if (this._htOption.dotScaleTiming_V) {
1609+
if (this._htOption.dotScaleTiming_V < 0 || this._htOption.dotScaleTiming_V > 1) {
1610+
console.warn(this._htOption.dotScaleTiming_V +
1611+
" , is invalidate, dotScaleTiming_V must greater than 0, less than or equal to 1, now reset to 1. "
1612+
)
1613+
this._htOption.dotScaleTiming_V = 1;
1614+
}
1615+
} else {
1616+
this._htOption.dotScaleTiming_V = this._htOption.dotScaleTiming;
1617+
}
1618+
1619+
1620+
1621+
if (this._htOption.dotScaleA < 0 || this._htOption.dotScaleA > 1) {
1622+
console.warn(this._htOption.dotScaleA +
1623+
" , is invalidate, dotScaleA must greater than 0, less than or equal to 1, now reset to 1. "
1624+
)
1625+
this._htOption.dotScaleA = 1;
1626+
}
1627+
if (this._htOption.dotScaleAO) {
1628+
if (this._htOption.dotScaleAO < 0 || this._htOption.dotScaleAO > 1) {
1629+
console.warn(this._htOption.dotScaleAO +
1630+
" , is invalidate, dotScaleAO must greater than 0, less than or equal to 1, now reset to 1. "
1631+
)
1632+
this._htOption.dotScaleAO = 1;
1633+
}
1634+
} else {
1635+
this._htOption.dotScaleAO = this._htOption.dotScaleA;
1636+
}
1637+
if (this._htOption.dotScaleAI) {
1638+
if (this._htOption.dotScaleAI < 0 || this._htOption.dotScaleAI > 1) {
1639+
console.warn(this._htOption.dotScaleAI +
1640+
" , is invalidate, dotScaleAI must greater than 0, less than or equal to 1, now reset to 1. "
1641+
)
1642+
this._htOption.dotScaleAI = 1;
1643+
}
1644+
} else {
1645+
this._htOption.dotScaleAI = this._htOption.dotScaleA;
1646+
}
1647+
1648+
1649+
15731650
if (this._htOption.backgroundImageAlpha < 0 || this._htOption.backgroundImageAlpha > 1) {
15741651
console.warn(this._htOption.backgroundImageAlpha +
15751652
" , is invalidate, backgroundImageAlpha must between 0 and 1, now reset to 1. ")

0 commit comments

Comments
 (0)