Class: Fontisan::Tables::Cff2::Index
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff2::Index
- Includes:
- Enumerable
- Defined in:
- lib/fontisan/tables/cff2/index.rb
Overview
Reads a CFF2 INDEX structure.
A CFF2 INDEX uses a 4-byte count (Card32) instead of the 2-byte count (Card16) used by CFF1. Otherwise the layout is the same: count, offSize, offset array (1-based), then data.
An empty INDEX is just the 4-byte count field (= 0).
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#off_size ⇒ Object
readonly
Returns the value of attribute off_size.
-
#offsets ⇒ Object
readonly
Returns the value of attribute offsets.
-
#start_offset ⇒ Object
readonly
Returns the value of attribute start_offset.
Class Method Summary collapse
-
.build(items) ⇒ String
Build an INDEX from a list of data items.
-
.read(raw_data, offset) ⇒ Object
Read a CFF2 INDEX at
offsetwithinraw_data.
Instance Method Summary collapse
-
#[](index) ⇒ String?
Fetch the item at
index(0-based). -
#each ⇒ Object
Iterate over all items.
- #empty? ⇒ Boolean
-
#initialize(io, start_offset = 0) ⇒ Index
constructor
A new instance of Index.
-
#to_a ⇒ Object
All items as an array.
-
#total_size ⇒ Object
Total size of the INDEX in bytes (count + offSize + offsets + data).
Constructor Details
#initialize(io, start_offset = 0) ⇒ Index
Returns a new instance of Index.
47 48 49 50 51 |
# File 'lib/fontisan/tables/cff2/index.rb', line 47 def initialize(io, start_offset = 0) @io = io @start_offset = start_offset parse! end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
24 25 26 |
# File 'lib/fontisan/tables/cff2/index.rb', line 24 def count @count end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
24 25 26 |
# File 'lib/fontisan/tables/cff2/index.rb', line 24 def data @data end |
#off_size ⇒ Object (readonly)
Returns the value of attribute off_size.
24 25 26 |
# File 'lib/fontisan/tables/cff2/index.rb', line 24 def off_size @off_size end |
#offsets ⇒ Object (readonly)
Returns the value of attribute offsets.
24 25 26 |
# File 'lib/fontisan/tables/cff2/index.rb', line 24 def offsets @offsets end |
#start_offset ⇒ Object (readonly)
Returns the value of attribute start_offset.
24 25 26 |
# File 'lib/fontisan/tables/cff2/index.rb', line 24 def start_offset @start_offset end |
Class Method Details
.build(items) ⇒ String
Build an INDEX from a list of data items. Delegates to Fontisan::Tables::Cff2::IndexBuilder.
41 42 43 |
# File 'lib/fontisan/tables/cff2/index.rb', line 41 def self.build(items) IndexBuilder.build(items) end |
.read(raw_data, offset) ⇒ Object
Read a CFF2 INDEX at offset within raw_data.
30 31 32 33 34 |
# File 'lib/fontisan/tables/cff2/index.rb', line 30 def self.read(raw_data, offset) io = StringIO.new(raw_data) io.seek(offset) new(io, offset) end |
Instance Method Details
#[](index) ⇒ String?
Fetch the item at index (0-based).
56 57 58 59 60 61 62 63 |
# File 'lib/fontisan/tables/cff2/index.rb', line 56 def [](index) return nil if index.negative? || index >= count return "".b if count.zero? start_pos = offsets[index] - 1 end_pos = offsets[index + 1] - 1 data[start_pos, end_pos - start_pos] end |
#each ⇒ Object
Iterate over all items.
66 67 68 69 70 |
# File 'lib/fontisan/tables/cff2/index.rb', line 66 def each return enum_for(:each) unless block_given? count.times { |i| yield self[i] } end |
#empty? ⇒ Boolean
77 78 79 |
# File 'lib/fontisan/tables/cff2/index.rb', line 77 def empty? count.zero? end |
#to_a ⇒ Object
All items as an array.
73 74 75 |
# File 'lib/fontisan/tables/cff2/index.rb', line 73 def to_a Array.new(count) { |i| self[i] } end |
#total_size ⇒ Object
Total size of the INDEX in bytes (count + offSize + offsets + data).
82 83 84 85 86 |
# File 'lib/fontisan/tables/cff2/index.rb', line 82 def total_size return 4 if count.zero? 4 + 1 + ((count + 1) * off_size) + data.bytesize end |