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(&block) ⇒ Object
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.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ttfunk/table/cff/index.rb', line 14 def [](index) return if index >= items_count entry_cache[index] ||= decode_item( index, data_reference_offset + offsets[index], offsets[index + 1] - offsets[index], ) end |
#each {|item| ... } ⇒ void #each ⇒ Enumerator
Iterate over index items.
32 33 34 35 36 37 38 |
# File 'lib/ttfunk/table/cff/index.rb', line 32 def each(&block) return to_enum(__method__) unless block items_count.times do |i| yield(self[i]) end end |
#encode(*args) ⇒ TTFunk::EncodedString
Encode index.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ttfunk/table/cff/index.rb', line 51 def encode(*args) new_items = encode_items(*args) if new_items.empty? return [0].pack('n') end if new_items.length > 0xffff raise Error, 'Too many items in a CFF index' end offsets_array = new_items .each_with_object([1]) { |item, offsets| offsets << (offsets.last + item.length) } offset_size = (offsets_array.last.bit_length / 8.0).ceil offsets_array.map! { |offset| encode_offset(offset, offset_size) } EncodedString.new.concat( [new_items.length, offset_size].pack('nC'), *offsets_array, *new_items, ) end |
#items_count ⇒ Integer
Numer of items in this index.
43 44 45 |
# File 'lib/ttfunk/table/cff/index.rb', line 43 def items_count items.length end |