Comments (7)
Convert text first, solved my problem.
function utf16to8(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 qrious.
My QR Code generator library has full Unicode support, including emoji / astral planes. Have a look at qrcodegen.js#L881.
from qrious.
correct code, that supports cyrillic & emojy would look like this:
function utf32to8 (str) {
var out, i, len, c;
out = "";
len = str.length;
var codeAt = str.codePointAt || str.charCodeAt; // IE 11 doesn't have codePointAt
for (i = 0; i < len; i++) {
c = codeAt.call(str, i);
if (c >= 0x10000) {
out += String.fromCharCode(0xF0 | ((c >> 18) & 0x07));
out += String.fromCharCode(0x80 | ((c >> 12) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
else if (c >= 0x0800) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
else if (c >= 0x0080) {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
else
out += str.charAt(i);
if (str.charCodeAt(i) != c)
i++;
}
return out;
}
P.S. issue with IE fixed
from qrious.
@wolfiesonfire Your code doesn't translate UTF-16 surrogate pairs into proper UTF-8 sequences. So any characters above U+FFFF will be broken. Also, your code needlessly escapes U+0000, resulting in illegal over-long UTF-8.
from qrious.
I'm not sure how to implement this but I'd love to! I'm open to any help that can be offered to see if we can support such characters or if it is even possible within the QR code specs.
from qrious.
ISO-8859-1 specification supports UTF-8 encoding by using the byte-mode. The qrcode.js project supports UTF-8 mode. I would take some time on making it work in this library.
from qrious.
@nayuki Thanks for explain, i see the problem now.
from qrious.
Related Issues (20)
- SVG generation HOT 4
- 生成二维码的字符串很长 HOT 2
- Demo broken HOT 4
- Unicode characters not working HOT 3
- 二维码能展示,但是用微信等扫描图片就扫描不出来 HOT 1
- Custom pattern QR Generator scanner and reader like facebook messenger?
- Qrious do not work when canvas read is disabled for privacy reasons HOT 2
- Is this project dead? HOT 1
- password protected qr code HOT 4
- padding not null toDataUrl Picture not centered HOT 3
- Get access to underlying modules? HOT 2
- How can I append QR code to already existing canvas element?
- Question about the LEVEL value HOT 2
- TypeError: Cannot set property 'QRious' of undefined HOT 3
- QR Code Structure HOT 1
- QRious not found since upgrade Chrome to latest version HOT 4
- The QR Generation is not working I dont know why. Heres the error Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'returnValues') at addproduct.php:152:124 at async addproduct.php:150:25
- compatibility with C sharp in VB 6
- License confusion
- What QR code format is used in the library?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qrious.