Unicode Variation Selectors in Ruby

107 views Asked by At

How do I encode a "Variation Selector" for a unicode code point in a Ruby string literal?

Background:

I render a PDF with the prawn gem where I use a font which has some glyphs which I need to encode with a variation selector. The code point is \u0031. I have read that I need to append the variation selector, but it doesn't seem to work, e.g. "\u{0031FE02}", "\u{0031}\u{FE02}" or "\u0031FE02".

1

There are 1 answers

0
Aleksei Matiushkin On BEST ANSWER

The answer might be disappointing: ruby does everything well, but your target system might be unable to draw the resulting character properly. Look (Ubuntu 15.04):

▶ "\u{0061}\u{0300}"
#⇒ "à"   # perfect
▶ "\u{0061}\u{fe10}"
#⇒ "a︐" # uhmmm, at least she tried
▶ "\u{0061}\u{fe02}"
#⇒ "a︂"   # disgusting

Unfortunately, the support for different variation selectors in operating systems is still very limited. You might try to look whether your system is able to draw the combined correctly here: http://unicode-table.com/en/#variation-selectors