Cyrllic characters in SVG font

时间:2015-06-15 14:41:06

标签: javascript svg unicode encoding fonts

You will have to bear with me with this, as I know very little about encodings so may be asking something very simple/obvious. I am working with some SVG fonts in browser-side Javascript and I need to pull out some information on Cyrillic characters grammatically.

I am doing this currently with latin characters, which is easy as they are stored like so:

<glyph unicode="I" horiz-adv-x="573" d="M139 0v1513h281v-1513h-281z" />

I can just parse the xml and do a match on "I" to get the information I need. However, I cannot see any Cyrillic characters in the XML. I can see many characters in the following format:

<glyph unicode="&#x25fc;" horiz-adv-x="1136" d="M0 0v1137h1137v-1137h-1137z" />

I have no idea what the code in the unicode attribute represents (other than a character in unicode format obviously).

Can anyone recommend how I could convert a Cyrillic character to this format? For example the character п.

UPDATE

I just did a bit of digging and found an article on wikipedia with a list of unicode characters. Looking at this list you can see that there is a column called 'Decimal' that matches the format in the example above. However if you go to the section of the list of Cyrillic chars there is no mention of decimal codes. Is this just because nobody has entered this information on the wiki?

1 个答案:

答案 0 :(得分:1)

п would be &#1087;

To get the code point of a unicode character in JavaScript you can use String.prototype.codePointAt method, in your case just type this into developer console:

"п".codePointAt(0)
// 1087

To convert the other way around:

String.fromCodePoint(1087)
// "п"

The format in your example, &#x... is a number in hexadecimal notation, so "п" could be also represented as &#x43f. Conversion:

(1087).toString(16)
// 43f

So the character &#xa8; in your comment would be ¨:

String.fromCodePoint( parseInt('a8', 16 ) )