Created
April 27, 2020 09:54
-
-
Save hotchpotch/c150199681482b2e5b7a7d1b5c4660fd to your computer and use it in GitHub Desktop.
TTF のフォントデータから含まれる文字をすべて出力する
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/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