Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TTF のフォントデータから含まれる文字をすべて出力する
#!/usr/bin/env ruby
#
# base: https://stackoverflow.com/questions/11895641/programmatically-get-a-list-of-characters-a-certain-ttf-font-file-supports
#
require 'ttfunk'
ttf_file = ARGV.shift
ttf = TTFunk::File.open ttf_file
cmap = ttf.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.chr("UTF-8") }.uniq
puts unicode_chars.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment