Class: TTFunk::Table::Cmap

Inherits:
TTFunk::Table show all
Defined in:
lib/ttfunk/table/cmap.rb,
lib/ttfunk/table/cmap/format00.rb,
lib/ttfunk/table/cmap/format04.rb,
lib/ttfunk/table/cmap/format06.rb,
lib/ttfunk/table/cmap/format10.rb,
lib/ttfunk/table/cmap/format12.rb,
lib/ttfunk/table/cmap/subtable.rb

Overview

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

Defined Under Namespace

Modules: Format00, Format04, Format06, Format10, Format12 Classes: Subtable

Instance Attribute Summary collapse

Attributes inherited from TTFunk::Table

#file, #length, #offset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TTFunk::Table

#exists?, #initialize, #raw, #tag

Constructor Details

This class inherits a constructor from TTFunk::Table

Instance Attribute Details

#tablesArray<TTFunk::Table::Cmap::Subtable> (readonly)

Encoding tables.

Returns:



13
14
15
# File 'lib/ttfunk/table/cmap.rb', line 13

def tables
  @tables
end

#versionInteger (readonly)

Table version.

Returns:

  • (Integer)


9
10
11
# File 'lib/ttfunk/table/cmap.rb', line 9

def version
  @version
end

Class Method Details

.encode(charmap, encoding) ⇒ Hash

Encode table.

Parameters:

  • charmap (Hash{Integer => Integer})
  • encoding (Symbol)

Returns:

  • (Hash)
    • ‘:charmap` (Hash{Integer => Hash}) keys are the characrers in `charset`, values are hashes:

      • ‘:old` (Integer) - glyph ID in the original font.

      • ‘:new` (Integer) - glyph ID in the subset font.

      that maps the characters in charmap to a

    • ‘:table` (String) - serialized table.

    • ‘:max_glyph_id` (Integer) - maximum glyph ID in the new font.



27
28
29
30
31
32
33
# 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

Instance Method Details

#unicodeArray<TTFunk::Table::Cmap::Subtable>

Get Unicode encoding records.

Returns:



38
39
40
41
42
43
44
45
# 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