mirror of
https://github.com/lrsjng/jquery-qrcode.git
synced 2026-08-13 04:11:36 +08:00
Refactors blank option.
This commit is contained in:
+32
-17
@@ -11,6 +11,7 @@
|
|||||||
var QRCode = function (version, level, text) {
|
var QRCode = function (version, level, text) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// `qrcode` is the single public function that will be defined by the `QR Code Generator`
|
// `qrcode` is the single public function that will be defined by the `QR Code Generator`
|
||||||
// at the end of the file.
|
// at the end of the file.
|
||||||
var qr = qrcode(version, level);
|
var qr = qrcode(version, level);
|
||||||
@@ -21,7 +22,33 @@
|
|||||||
this.level = level;
|
this.level = level;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.moduleCount = qr.getModuleCount();
|
this.moduleCount = qr.getModuleCount();
|
||||||
this.isDark = function (col, row) { return qr.isDark(col, row); };
|
|
||||||
|
this.isDark = function (col, row) {
|
||||||
|
|
||||||
|
return qr.isDark(col, row);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.extIsDarkFn = function (width, height, blank) {
|
||||||
|
|
||||||
|
if (!blank) {
|
||||||
|
return this.isDark;
|
||||||
|
}
|
||||||
|
|
||||||
|
var moduleCount = qr.getModuleCount(),
|
||||||
|
moduleWidth = width / moduleCount,
|
||||||
|
moduleHeight = height / moduleCount;
|
||||||
|
|
||||||
|
return function (row, col) {
|
||||||
|
|
||||||
|
var l = col * moduleWidth,
|
||||||
|
t = row * moduleHeight,
|
||||||
|
r = l + moduleWidth,
|
||||||
|
b = t + moduleHeight;
|
||||||
|
|
||||||
|
return qr.isDark(row, col) && (blank.l > r || l > blank.r || blank.t > b || t > blank.b);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -77,25 +104,13 @@
|
|||||||
var moduleCount = qr.moduleCount,
|
var moduleCount = qr.moduleCount,
|
||||||
moduleWidth = settings_width / moduleCount,
|
moduleWidth = settings_width / moduleCount,
|
||||||
moduleHeight = settings_height / moduleCount,
|
moduleHeight = settings_height / moduleCount,
|
||||||
row, col,
|
isDarkFn = qr.extIsDarkFn(settings_width, settings_height, settings_blank),
|
||||||
forceBlank = function () { return false; };
|
row, col;
|
||||||
|
|
||||||
if (settings_blank) {
|
|
||||||
forceBlank = function (row, col) {
|
|
||||||
|
|
||||||
var l = settings_left + col * moduleWidth,
|
|
||||||
t = settings_top + row * moduleHeight,
|
|
||||||
r = l + moduleWidth,
|
|
||||||
b = t + moduleHeight;
|
|
||||||
|
|
||||||
return settings_blank.l <= r && l <= settings_blank.r && settings_blank.t <= b && t <= settings_blank.b;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
for (row = 0; row < moduleCount; row += 1) {
|
for (row = 0; row < moduleCount; row += 1) {
|
||||||
for (col = 0; col < moduleCount; col += 1) {
|
for (col = 0; col < moduleCount; col += 1) {
|
||||||
if (qr.isDark(row, col) && !forceBlank(row, col)) {
|
if (isDarkFn(row, col)) {
|
||||||
ctx.rect(settings_left + col * moduleWidth, settings_top + row * moduleHeight, moduleWidth, moduleHeight);
|
ctx.rect(settings_left + col * moduleWidth, settings_top + row * moduleHeight, moduleWidth, moduleHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,7 +231,7 @@
|
|||||||
// the encoded text
|
// the encoded text
|
||||||
text: 'no text',
|
text: 'no text',
|
||||||
|
|
||||||
// blank space: {l, t, r, b}
|
// blank space: {l: 0, t: 0, r: 0, b: 0} in px relative to QR code space
|
||||||
blank: null
|
blank: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user