Skip to content

Instantly share code, notes, and snippets.

@ArsnealX
Created May 19, 2016 07:11
Show Gist options
  • Save ArsnealX/4d9e2fbfc4c2d73fc1ac05dd0471477e to your computer and use it in GitHub Desktop.
Save ArsnealX/4d9e2fbfc4c2d73fc1ac05dd0471477e to your computer and use it in GitHub Desktop.
equire 'ttfunk'
file = TTFunk::File.open("/path/to/fontfile.ttf")
cmap = file.cmap
chars = {}
unicode_chars = []
cmap.tables.each do |subtable|
next if !subtable.unicode?
chars = chars.merge( subtable.code_map )
end
unicode_chars = chars.keys.map{ |dec| [dec.to_s(16).hex].pack('U') }
puts "\n -- Found #{unicode_chars.length} characters in this font \n\n"
p unicode_chars
File.open('/path/to/outputs.txt', 'w').write unicode_chars.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment