class TTFunk::Table::Cmap

Character to Glyph Index Mapping (‘cmap`) table.

Attributes

tables[R]

Encoding tables. @return [Array<TTFunk::Table::Cmap::Subtable>]

version[R]

Table version. @return [Integer]

Public Class Methods

encode(charmap, encoding) click to toggle source

Encode table.

@param charmap [Hash{Integer => Integer}] @param encoding [Symbol] @return [Hash]

* `:charmap` (<tt>Hash{Integer => Hash}</tt>) keys are the characrers in
  `charset`, values are hashes:
  * `:old` (<tt>Integer</tt>) - glyph ID in the original font.
  * `:new` (<tt>Integer</tt>) - glyph ID in the subset font.
  that maps the characters in charmap to a
* `:table` (<tt>String</tt>) - serialized table.
* `:max_glyph_id` (<tt>Integer</tt>) - maximum glyph ID in the new font.
# File lib/ttfunk/table/cmap.rb, line 27
def self.encode(charmap, encoding)
  result = Cmap::Subtable.encode(charmap, encoding)

  # pack 'version' and 'table-count'
  result[:table] = [0, 1, result.delete(:subtable)].pack('nnA*')
  result
end

Public Instance Methods

unicode() click to toggle source

Get Unicode encoding records.

@return [Array<TTFunk::Table::Cmap::Subtable>]

# File lib/ttfunk/table/cmap.rb, line 38
def unicode
  # Because most callers just call .first on the result, put tables with
  # highest-number format first. Unsupported formats will be ignored.
  @unicode ||=
    @tables
      .select { |table| table.unicode? && table.supported? }
      .sort { |a, b| b.format <=> a.format }
end

Private Instance Methods

parse!() click to toggle source
# File lib/ttfunk/table/cmap.rb, line 49
def parse!
  @version, table_count = read(4, 'nn')
  @tables =
    Array.new(table_count) do
      Cmap::Subtable.new(file, offset)
    end
end