Class: TTFunk::Table::Loca
- Inherits:
-
TTFunk::Table
- Object
- TTFunk::Table
- TTFunk::Table::Loca
- Defined in:
- lib/ttfunk/table/loca.rb
Overview
Index to Location table.
Instance Attribute Summary collapse
-
#offsets ⇒ Array<Integer>
readonly
Glyph ofsets.
Attributes inherited from TTFunk::Table
Class Method Summary collapse
-
.encode(offsets) ⇒ Hash
Encode table.
Instance Method Summary collapse
-
#index_of(glyph_id) ⇒ Integer
Glyph offset by ID.
-
#size_of(glyph_id) ⇒ Integer
Size of encoded glyph.
Methods inherited from TTFunk::Table
#exists?, #initialize, #raw, #tag
Constructor Details
This class inherits a constructor from TTFunk::Table
Instance Attribute Details
#offsets ⇒ Array<Integer> (readonly)
Glyph ofsets
11 12 13 |
# File 'lib/ttfunk/table/loca.rb', line 11 def offsets @offsets end |
Class Method Details
.encode(offsets) ⇒ Hash
Encode table.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ttfunk/table/loca.rb', line 22 def self.encode(offsets) long_offsets = offsets.any? { |offset| short_offset = offset / 2 short_offset * 2 != offset || short_offset > 0xffff } if long_offsets { type: 1, table: offsets.pack('N*') } else { type: 0, table: offsets.map { |o| o / 2 }.pack('n*') } end end |
Instance Method Details
#index_of(glyph_id) ⇒ Integer
Glyph offset by ID.
40 41 42 |
# File 'lib/ttfunk/table/loca.rb', line 40 def index_of(glyph_id) @offsets[glyph_id] end |
#size_of(glyph_id) ⇒ Integer
Size of encoded glyph.
48 49 50 |
# File 'lib/ttfunk/table/loca.rb', line 48 def size_of(glyph_id) @offsets[glyph_id + 1] - @offsets[glyph_id] end |