class TTFunk::Table::Name
Attributes
compatible_full[R]
copyright[R]
description[R]
designer[R]
designer_url[R]
font_family[R]
font_name[R]
font_subfamily[R]
license[R]
license_url[R]
manufacturer[R]
preferred_family[R]
preferred_subfamily[R]
sample_text[R]
strings[R]
trademark[R]
unique_subfamily[R]
vendor_url[R]
version[R]
Public Class Methods
encode(names, key = '')
click to toggle source
# File lib/ttfunk/table/name.rb, line 47 def self.encode(names, key = '') tag = Digest::SHA1.hexdigest(key)[0, 6] postscript_name = Name::String.new( "#{tag}+#{names.postscript_name}", 1, 0, 0 ) strings = names.strings.dup strings[6] = [postscript_name] str_count = strings.inject(0) { |sum, (_, list)| sum + list.length } table = [0, str_count, 6 + 12 * str_count].pack('n*') strtable = '' strings.each do |id, list| list.each do |string| table << [ string.platform_id, string.encoding_id, string.language_id, id, string.length, strtable.length ].pack('n*') strtable << string end end table << strtable end
Public Instance Methods
postscript_name()
click to toggle source
# File lib/ttfunk/table/name.rb, line 74 def postscript_name return @postscript_name if @postscript_name font_family.first || 'unnamed' end
Private Instance Methods
parse!()
click to toggle source
# File lib/ttfunk/table/name.rb, line 81 def parse! count, string_offset = read(6, 'x2n*') entries = [] count.times do platform, encoding, language, id, length, start_offset = read(12, 'n*') entries << { platform_id: platform, encoding_id: encoding, language_id: language, name_id: id, length: length, offset: offset + string_offset + start_offset } end @strings = Hash.new { |h, k| h[k] = [] } count.times do |i| io.pos = entries[i][:offset] text = io.read(entries[i][:length]) @strings[entries[i][:name_id]] << Name::String.new( text, entries[i][:platform_id], entries[i][:encoding_id], entries[i][:language_id] ) end @copyright = @strings[0] @font_family = @strings[1] @font_subfamily = @strings[2] @unique_subfamily = @strings[3] @font_name = @strings[4] @version = @strings[5] # should only be ONE postscript name @postscript_name = @strings[6].first.strip_extended @trademark = @strings[7] @manufacturer = @strings[8] @designer = @strings[9] @description = @strings[10] @vendor_url = @strings[11] @designer_url = @strings[12] @license = @strings[13] @license_url = @strings[14] @preferred_family = @strings[16] @preferred_subfamily = @strings[17] @compatible_full = @strings[18] @sample_text = @strings[19] end