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.
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 86
86 | def initialize(file, table_start) |
87 | @file = file |
88 | @platform_id, @encoding_id, @offset = read(8, 'nnN') |
89 | @offset += table_start |
90 | |
91 | parse_from(@offset) do |
92 | @format = read(2, 'n').first |
93 | |
94 | case @format |
95 | when 0 then extend(TTFunk::Table::Cmap::Format00) |
96 | when 4 then extend(TTFunk::Table::Cmap::Format04) |
97 | when 6 then extend(TTFunk::Table::Cmap::Format06) |
98 | when 10 then extend(TTFunk::Table::Cmap::Format10) |
99 | when 12 then extend(TTFunk::Table::Cmap::Format12) |
100 | end
|
101 | |
102 | parse_cmap!
|
103 | end
|
104 | end
|
Instance Attribute Details
#encoding_id ⇒ Integere (readonly)
Platform-specific encoding ID.
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 25
25 | def encoding_id |
26 | @encoding_id
|
27 | end
|
#format ⇒ Integer (readonly)
Record encoding format.
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 29
29 | def format |
30 | @format
|
31 | end
|
#platform_id ⇒ Integer (readonly)
Platform ID.
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 21
21 | def platform_id |
22 | @platform_id
|
23 | end
|
Class Method Details
.encode(charmap, encoding) ⇒ Hash
Encode encoding record.
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 56
56 | def self.encode(charmap, encoding) |
57 | case encoding |
58 | when :mac_roman |
59 | result = Format00.encode(charmap) |
60 | when :unicode |
61 | result = Format04.encode(charmap) |
62 | when :unicode_ucs4 |
63 | result = Format12.encode(charmap) |
64 | else
|
65 | raise NotImplementedError, |
66 | "encoding #{encoding.inspect} is not supported" |
67 | end
|
68 | |
69 | mapping = ENCODING_MAPPINGS[encoding] |
70 | |
71 | # platform-id, encoding-id, offset
|
72 | result.merge( |
73 | platform_id: mapping[:platform_id], |
74 | encoding_id: mapping[:encoding_id], |
75 | subtable: [ |
76 | mapping[:platform_id], |
77 | mapping[:encoding_id], |
78 | 12, |
79 | result[:subtable], |
80 | ].pack('nnNA*'), |
81 | )
|
82 | end
|
Instance Method Details
#[](_code) ⇒ Integer
Get glyph ID for character code.
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 125
125 | def [](_code) |
126 | raise NotImplementedError, "cmap format #{@format} is not supported" |
127 | end
|
#supported? ⇒ Boolean
Is this encoding record format supported?
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 117
117 | def supported? |
118 | false
|
119 | end
|
#unicode? ⇒ Boolean
Is this an encoding record for Unicode?
Source Code
lib/ttfunk/table/cmap/subtable.rb, line 109
109 | def unicode? |
110 | (platform_id == 3 && (encoding_id == 1 || encoding_id == 10) && format != 0) || |
111 | (platform_id.zero? && format != 0) |
112 | end
|