Class: TTFunk::Table::Cff::Index
- Includes:
- Enumerable
- Defined in:
- lib/ttfunk/table/cff/index.rb
Overview
CFF Index.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from SubTable
Instance Method Summary collapse
-
#[](index) ⇒ any
Get value by index.
-
#each {|item| ... } ⇒ void
#each ⇒ Enumerator
Iterate over index items.
-
#encode(*args) ⇒ TTFunk::EncodedString
Encode index.
-
#items_count ⇒ Integer
Numer of items in this index.
Methods inherited from SubTable
Constructor Details
This class inherits a constructor from TTFunk::SubTable
Instance Method Details
#[](index) ⇒ any
Get value by index.
Source Code
lib/ttfunk/table/cff/index.rb, line 14
14 | def [](index) |
15 | return if index >= items_count |
16 | |
17 | entry_cache[index] ||= |
18 | decode_item( |
19 | index, |
20 | data_reference_offset + offsets[index], |
21 | offsets[index + 1] - offsets[index], |
22 | )
|
23 | end
|
#each {|item| ... } ⇒ void #each ⇒ Enumerator
Iterate over index items.
Source Code
lib/ttfunk/table/cff/index.rb, line 32
32 | def each(&block) |
33 | return to_enum(__method__) unless block |
34 | |
35 | items_count.times do |i| |
36 | yield(self[i]) |
37 | end
|
38 | end
|
#encode(*args) ⇒ TTFunk::EncodedString
Encode index.
Source Code
lib/ttfunk/table/cff/index.rb, line 51
51 | def encode(*args) |
52 | new_items = encode_items(*args) |
53 | |
54 | if new_items.empty? |
55 | return [0].pack('n') |
56 | end
|
57 | |
58 | if new_items.length > 0xffff |
59 | raise Error, 'Too many items in a CFF index' |
60 | end
|
61 | |
62 | offsets_array = |
63 | new_items
|
64 | .each_with_object([1]) { |item, offsets| |
65 | offsets << (offsets.last + item.length) |
66 | }
|
67 | |
68 | offset_size = (offsets_array.last.bit_length / 8.0).ceil |
69 | |
70 | offsets_array.map! { |offset| encode_offset(offset, offset_size) } |
71 | |
72 | EncodedString.new.concat( |
73 | [new_items.length, offset_size].pack('nC'), |
74 | *offsets_array, |
75 | *new_items, |
76 | )
|
77 | end
|
#items_count ⇒ Integer
Numer of items in this index.
Source Code
lib/ttfunk/table/cff/index.rb, line 43
43 | def items_count |
44 | items.length |
45 | end
|