From 9bfca9a80fda4505bdcb2699c115ba9622a94631 Mon Sep 17 00:00:00 2001 From: Eric Dum Date: Sat, 21 Dec 2013 01:22:37 +0800 Subject: [PATCH 1/2] Resolve UTF8 support, that is supported Chinese --- qrcode.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/qrcode.js b/qrcode.js index 41afbc4..a40853a 100644 --- a/qrcode.js +++ b/qrcode.js @@ -20,7 +20,7 @@ function QR8bitByte(data) { this.mode = QRMode.MODE_8BIT_BYTE; - this.data = data; + this.data = this.toUTF8(data); } QR8bitByte.prototype = { @@ -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; } }; From 61455486efccdd21ba9327193af0bb44a8290982 Mon Sep 17 00:00:00 2001 From: Eric Dum Date: Tue, 7 Jan 2014 16:06:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README b/README index b7578cb..2925a05 100644 --- a/README +++ b/README @@ -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: ---