Class: TTFunk::Table::Cff::Index

Inherits:
SubTable
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ttfunk/table/cff/index.rb

Overview

CFF Index.

Direct Known Subclasses

CharstringsIndex, FontIndex, SubrIndex, TopIndex

Instance Attribute Summary

Attributes inherited from SubTable

#file, #length, #table_offset

Instance Method Summary collapse

Methods inherited from SubTable

#eot?, #initialize, #read

Constructor Details

This class inherits a constructor from TTFunk::SubTable

Instance Method Details

#[](index) ⇒ any

Get value by index.

Parameters:

  • index (Integer)

Returns:

  • (any)
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 #eachEnumerator

Iterate over index items.

Overloads:

  • #each {|item| ... } ⇒ void

    This method returns an undefined value.

    Yield Parameters:

    • item (any)
  • #eachEnumerator

    Returns:

    • (Enumerator)
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.

Parameters:

  • args

    all arguments are passed to encode_item method.

Returns:

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_countInteger

Numer of items in this index.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/cff/index.rb, line 43
43
def items_count
44
  items.length
45
end