Last active
November 1, 2016 09:30
-
-
Save Konstantinusz/b4c42e2ee5b8df22414652ca66802d28 to your computer and use it in GitHub Desktop.
Checks if a ttf file (true type font) supports a given unicode codepoint (must be given as a 4 char hexa code, eg 2666 for BLACK DIAMOND SUIT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
ttf=ARGV[0] | |
cp=ARGV[1].rjust(4,"0") | |
cp1="00"+cp[0..1] | |
cp2=cp[2..3] | |
s=%x{fc-query "#{ttf}"} | |
charset=s.scan(/charset: \n\t(.*?)\n[^\t]/m).flatten[0].split("\n\t") | |
row=charset.find{|r| r=~/^#{cp1}: /} | |
if row==nil then | |
puts "not supported" | |
else | |
num=cp2.to_i(16) | |
section_index=num/32 | |
section=row.split(" ")[section_index+1] | |
binary=section.split(//).map{|z| z.to_i(16).to_s(2).rjust(4,"0")}.join | |
index=num % 32 | |
if binary[index]=="0" then | |
puts "not supported" | |
else | |
puts "supported" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment