Giter Site home page Giter Site logo

Is there any non ascii support? about qrious HOT 7 OPEN

neocotic avatar neocotic commented on July 16, 2024 2
Is there any non ascii support?

from qrious.

Comments (7)

wolfiesonfire avatar wolfiesonfire commented on July 16, 2024 3

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.

nayuki avatar nayuki commented on July 16, 2024 2

My QR Code generator library has full Unicode support, including emoji / astral planes. Have a look at qrcodegen.js#L881.

from qrious.

se-ti avatar se-ti commented on July 16, 2024 2

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.

nayuki avatar nayuki commented on July 16, 2024 1

@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.

neocotic avatar neocotic commented on July 16, 2024

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.

dsh0416 avatar dsh0416 commented on July 16, 2024

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.

wolfiesonfire avatar wolfiesonfire commented on July 16, 2024

@nayuki Thanks for explain, i see the problem now.

from qrious.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.