ruby – 以编程方式获取某个.ttf字体文件支持的字符列表
发布时间:2020-12-17 03:54:19 所属栏目:百科 来源:网络整理
导读:有没有办法以编程方式获取.ttf文件支持使用 Ruby和/或Bash的字符列表.我试图将支持的字符代码传输到文??本文件中以供以后处理. (我不想使用Font Forge.) 解决方法 找到一个名为ttfunk的Ruby gem,可以找到 here. 在gem安装ttfunk之后,您可以通过运行以下脚本
有没有办法以编程方式获取.ttf文件支持使用
Ruby和/或Bash的字符列表.我试图将支持的字符代码传输到文??本文件中以供以后处理.
(我不想使用Font Forge.) 解决方法
找到一个名为ttfunk的Ruby gem,可以找到
here.
在gem安装ttfunk之后,您可以通过运行以下脚本来获取所有unicode字符: require 'ttfunk' file = TTFunk::File.open("path/to/font.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) } puts "n -- Found #{unicode_chars.length} characters in this font nn" p unicode_chars 这将输出如下内容: - Found 2815 characters in this font ["20","21","22","23",...,"fef8","fef9","fefa","fefb","fefc","fffc","ffff"] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |