Class: TTFunk::Table::Cmap::Subtable

Inherits:
Object
  • Object
show all
Includes:
Reader
Defined in:
lib/ttfunk/table/cmap/subtable.rb

Constant Summary collapse

ENCODING_MAPPINGS =
{
  :mac_roman    => { :platform_id => 1, :encoding_id => 0 },
  # use microsoft unicode, instead of generic unicode, for optimal windows support
  :unicode      => { :platform_id => 3, :encoding_id => 1 },
  :unicode_ucs4 => { :platform_id => 3, :encoding_id => 10 }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, table_start) ⇒ Subtable

Returns a new instance of Subtable.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ttfunk/table/cmap/subtable.rb', line 41

def initialize(file, table_start)
  @file = file
  @platform_id, @encoding_id, @offset = read(8, "nnN")
  @offset += table_start

  parse_from(@offset) do
    @format = read(2, "n").first

    case @format
      when 0  then extend(TTFunk::Table::Cmap::Format00)
      when 4  then extend(TTFunk::Table::Cmap::Format04)
      when 6  then extend(TTFunk::Table::Cmap::Format06)
      when 10 then extend(TTFunk::Table::Cmap::Format10)
      when 12 then extend(TTFunk::Table::Cmap::Format12)
    end

    parse_cmap!
  end
end

Instance Attribute Details

#encoding_idObject (readonly)

Returns the value of attribute encoding_id.



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

def encoding_id
  @encoding_id
end

#formatObject (readonly)

Returns the value of attribute format.



11
12
13
# File 'lib/ttfunk/table/cmap/subtable.rb', line 11

def format
  @format
end

#platform_idObject (readonly)

Returns the value of attribute platform_id.



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

def platform_id
  @platform_id
end

Class Method Details

.encode(charmap, encoding) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ttfunk/table/cmap/subtable.rb', line 20

def self.encode(charmap, encoding)
  case encoding
  when :mac_roman
    result = Format00.encode(charmap)
  when :unicode
    result = Format04.encode(charmap)
  when :unicode_ucs4
    result = Format12.encode(charmap)
  else
    raise NotImplementedError, "encoding #{encoding.inspect} is not supported"
  end

  mapping = ENCODING_MAPPINGS[encoding]

  # platform-id, encoding-id, offset
  result[:subtable] = [mapping[:platform_id], mapping[:encoding_id],
    12, result[:subtable]].pack("nnNA*")

  return result
end

Instance Method Details

#[](code) ⇒ Object

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/ttfunk/table/cmap/subtable.rb', line 70

def [](code)
  raise NotImplementedError, "cmap format #{@format} is not supported"
end

#supported?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ttfunk/table/cmap/subtable.rb', line 66

def supported?
  false
end

#unicode?Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/ttfunk/table/cmap/subtable.rb', line 61

def unicode?
  platform_id == 3 && (encoding_id == 1 || encoding_id == 10) && format != 0 ||
  platform_id == 0 && format != 0
end