class TTFunk::Table::Name
Naming (‘name`) table
Constants
- COMPATIBLE_FULL_NAME_ID
Compatible Full ID.
- COPYRIGHT_NAME_ID
Copyright notice ID.
- DESCRIPTION_NAME_ID
Description ID.
- DESIGNER_NAME_ID
Designer ID.
- DESIGNER_URL_NAME_ID
Designer URL ID.
- FONT_FAMILY_NAME_ID
Font Family name ID.
- FONT_NAME_NAME_ID
Full font name that reflects all family and relevant subfamily descriptors ID.
- FONT_SUBFAMILY_NAME_ID
Font Subfamily name ID.
- LICENSE_NAME_ID
License Description ID.
- LICENSE_URL_NAME_ID
License Info URL ID.
- MANUFACTURER_NAME_ID
Manufacturer
Name
ID.- POSTSCRIPT_NAME_NAME_ID
PostScript name for the font ID.
- PREFERRED_FAMILY_NAME_ID
Typographic Family name ID.
- PREFERRED_SUBFAMILY_NAME_ID
Typographic Subfamily name ID.
- SAMPLE_TEXT_NAME_ID
Sample text ID.
- TRADEMARK_NAME_ID
Trademark ID.
- UNIQUE_SUBFAMILY_NAME_ID
Unique font identifier ID.
- VENDOR_URL_NAME_ID
Vendor URL ID.
- VERSION_NAME_ID
Version string ID.
Attributes
Compatible Full Names. @return [Array<NameString>]
Copyright notice. @return [Array<NameString>]
Descriptions. @return [Array<NameString>]
Designers. @return [Array<NameString>]
Designer URLs. @return [Array<NameString>]
Name
records. @return [Array<Hash>]
Font Family names. @return [Array<NameString>]
Full font names. @return [Array<NameString>]
Font Subfamily names. @return [Array<NameString>]
License Descriptions. @return [Array<NameString>]
License Info URLs. @return [Array<NameString>]
Manufacturer Names. @return [Array<NameString>]
Typographic Family names. @return [Array<NameString>]
Typographic Subfamily names. @return [Array<NameString>]
Sample texts. @return [Array<NameString>]
Name
strings. @return [Hash{Integer => NameString}]
Trademarks. @return [Array<NameString>]
Unique font identifiers. @return [Array<NameString>]
Vendor URLs. @return [Array<NameString>]
Version strings. @return [Array<NameString>]
Public Class Methods
Encode table.
@param names [TTFunk::Table::Name] @param key [String] @return [String]
# File lib/ttfunk/table/name.rb, line 187 def self.encode(names, key = '') tag = Digest::SHA1.hexdigest(key)[0, 6] postscript_name = NameString.new("#{tag}+#{names.postscript_name}", 1, 0, 0) strings = names.strings.dup strings[6] = [postscript_name] str_count = strings.reduce(0) { |sum, (_, list)| sum + list.length } table = [0, str_count, 6 + (12 * str_count)].pack('n*') strtable = +'' items = [] strings.each do |id, list| list.each do |string| items << [id, string] end end items = items.sort_by { |id, string| [string.platform_id, string.encoding_id, string.language_id, id] } items.each do |id, string| table << [ string.platform_id, string.encoding_id, string.language_id, id, string.length, strtable.length, ].pack('n*') strtable << string end table << strtable end
Public Instance Methods
PostScript name for the font. @return [String]
# File lib/ttfunk/table/name.rb, line 222 def postscript_name return @postscript_name if @postscript_name font_family.first || 'unnamed' end
Private Instance Methods
# File lib/ttfunk/table/name.rb, line 230 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, text: nil, } end @strings = Hash.new { |h, k| h[k] = [] } count.times do |i| io.pos = @entries[i][:offset] @entries[i][:text] = io.read(@entries[i][:length]) @strings[@entries[i][:name_id]] << NameString.new( @entries[i][:text] || '', @entries[i][:platform_id], @entries[i][:encoding_id], @entries[i][:language_id], ) end # should only be ONE postscript name @copyright = @strings[COPYRIGHT_NAME_ID] @font_family = @strings[FONT_FAMILY_NAME_ID] @font_subfamily = @strings[FONT_SUBFAMILY_NAME_ID] @unique_subfamily = @strings[UNIQUE_SUBFAMILY_NAME_ID] @font_name = @strings[FONT_NAME_NAME_ID] @version = @strings[VERSION_NAME_ID] unless @strings[POSTSCRIPT_NAME_NAME_ID].empty? @postscript_name = @strings[POSTSCRIPT_NAME_NAME_ID] .first.strip_extended end @trademark = @strings[TRADEMARK_NAME_ID] @manufacturer = @strings[MANUFACTURER_NAME_ID] @designer = @strings[DESIGNER_NAME_ID] @description = @strings[DESCRIPTION_NAME_ID] @vendor_url = @strings[VENDOR_URL_NAME_ID] @designer_url = @strings[DESIGNER_URL_NAME_ID] @license = @strings[LICENSE_NAME_ID] @license_url = @strings[LICENSE_URL_NAME_ID] @preferred_family = @strings[PREFERRED_FAMILY_NAME_ID] @preferred_subfamily = @strings[PREFERRED_SUBFAMILY_NAME_ID] @compatible_full = @strings[COMPATIBLE_FULL_NAME_ID] @sample_text = @strings[SAMPLE_TEXT_NAME_ID] end