Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the character corresponding to a Unicode character name?

I'm developing a Braille-to-text translator, and a nice feature to have is showing an output in Unicode's Braille patterns characters (say, kind of a Unicode Braille generator).

Since I know the dots that are "enabled" in each cell ("Braille character"), it would be trivial to construct the Unicode name of the character I need (they are of the form of BRAILLE PATTERN DOTS-123456 if they are all enabled, or BRAILLE PATTERN DOTS-14 if only dots 1 and 4 are enabled.

Is there any simple method to get a Unicode character in Javascript from its Unicode name?

My second try will be math*ing* with the Unicode values, but I think constructing the names is pretty much straightforward.

Thanks in advance :)

like image 502
mgarciaisaia Avatar asked Oct 03 '22 17:10

mgarciaisaia


2 Answers

JavaScript, unlike some other languages, does not have any direct way of getting a character from its Unicode name. In my full Unicode input utility, I have therefore used the brute force method of using the Unicode character data base as a text block and parsing it. You might find some better, more efficient and more maintainable tools, but if you need just some specific collections of characters as in the question, an ad hoc approach is better. In this case, you don’t even need the Unicode names as such; they would be just an intermediate step from dot patterns to characters.

Clause 15.11 in the Unicode Standard, chapter 15, describes the allocation principles for Braille symbols.

like image 135
Jukka K. Korpela Avatar answered Oct 07 '22 19:10

Jukka K. Korpela


Very interesting. In my app. I use a DB look up as you described and then use Javascript and the html canvas object to dynamically construct the Braille. This has the added benefit that I can create custom ARIA tags if desired. I say this because ASCII braille and Unicode aren't readable formats by several if not all Screen Readers. I know VoiceOver on iOS and Mac's won't read it. Something I'm working on is a way to make JS read BRL ASCII fields & Unicode and create ARIA tags so that a blind user actual knows what's going on on the webpage.

like image 25
CertDoctor Avatar answered Oct 07 '22 18:10

CertDoctor