Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
This example shows how you can create a QR Code PNG using Javascript and HTML5.
支持中文

Demo:
https://chrome.google.com/webstore/detail/sweet-qr-code-maker/hejblflceieoemjadbnlpplaajbneedn

Notes:
---
Expand Down
22 changes: 21 additions & 1 deletion qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

function QR8bitByte(data) {
this.mode = QRMode.MODE_8BIT_BYTE;
this.data = data;
this.data = this.toUTF8(data);
}

QR8bitByte.prototype = {
Expand All @@ -34,6 +34,26 @@ QR8bitByte.prototype = {
// not JIS ...
buffer.put(this.data.charCodeAt(i), 8);
}
},

toUTF8 : function(str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
};

Expand Down