Class: TTFunk::Table::Cmap::Subtable
- Inherits:
-
Object
- Object
- TTFunk::Table::Cmap::Subtable
- Includes:
- Reader
- Defined in:
- lib/ttfunk/table/cmap/subtable.rb
Overview
Character to Glyph Index encoding record. This class can be extended with a format-specific
Constant Summary collapse
- ENCODING_MAPPINGS =
Most used encoding mappings.
{ mac_roman: { platform_id: 1, encoding_id: 0 }.freeze, # Use microsoft unicode, instead of generic unicode, for optimal # Windows support unicode: { platform_id: 3, encoding_id: 1 }.freeze, unicode_ucs4: { platform_id: 3, encoding_id: 10 }.freeze, }.freeze
Instance Attribute Summary collapse
-
#encoding_id ⇒ Integere
readonly
Platform-specific encoding ID.
-
#format ⇒ Integer
readonly
Record encoding format.
-
#platform_id ⇒ Integer
readonly
Platform ID.
Class Method Summary collapse
-
.encode(charmap, encoding) ⇒ Hash
Encode encoding record.
Instance Method Summary collapse
-
#[](_code) ⇒ Integer
Get glyph ID for character code.
-
#initialize(file, table_start) ⇒ Subtable
constructor
A new instance of Subtable.
-
#supported? ⇒ Boolean
Is this encoding record format supported?.
-
#unicode? ⇒ Boolean
Is this an encoding record for Unicode?.
Constructor Details
#initialize(file, table_start) ⇒ Subtable
Returns a new instance of Subtable.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 86 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_id ⇒ Integere (readonly)
Platform-specific encoding ID.
25 26 27 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 25 def encoding_id @encoding_id end |
#format ⇒ Integer (readonly)
Record encoding format.
29 30 31 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 29 def format @format end |
#platform_id ⇒ Integer (readonly)
Platform ID.
21 22 23 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 21 def platform_id @platform_id end |
Class Method Details
.encode(charmap, encoding) ⇒ Hash
Encode encoding record.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 56 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.merge( platform_id: mapping[:platform_id], encoding_id: mapping[:encoding_id], subtable: [ mapping[:platform_id], mapping[:encoding_id], 12, result[:subtable], ].pack('nnNA*'), ) end |
Instance Method Details
#[](_code) ⇒ Integer
Get glyph ID for character code.
125 126 127 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 125 def [](_code) raise NotImplementedError, "cmap format #{@format} is not supported" end |
#supported? ⇒ Boolean
Is this encoding record format supported?
117 118 119 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 117 def supported? false end |
#unicode? ⇒ Boolean
Is this an encoding record for Unicode?
109 110 111 112 |
# File 'lib/ttfunk/table/cmap/subtable.rb', line 109 def unicode? (platform_id == 3 && (encoding_id == 1 || encoding_id == 10) && format != 0) || (platform_id.zero? && format != 0) end |