Skip to content

Instantly share code, notes, and snippets.

@hotchpotch
Created April 27, 2020 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotchpotch/c150199681482b2e5b7a7d1b5c4660fd to your computer and use it in GitHub Desktop.
Save hotchpotch/c150199681482b2e5b7a7d1b5c4660fd to your computer and use it in GitHub Desktop.
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