Class: TTFunk::Table::Loca

Inherits:
TTFunk::Table show all
Defined in:
lib/ttfunk/table/loca.rb

Instance Attribute Summary collapse

Attributes inherited from TTFunk::Table

#file, #length, #offset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TTFunk::Table

#exists?, #initialize, #raw, #tag

Constructor Details

This class inherits a constructor from TTFunk::Table

Instance Attribute Details

#offsetsObject (readonly)

Returns the value of attribute offsets.



6
7
8
# File 'lib/ttfunk/table/loca.rb', line 6

def offsets
  @offsets
end

Class Method Details

.encode(offsets) ⇒ Object

Accepts an array of offsets, with each index corresponding to the glyph id with that index.

Returns a hash containing:

  • :table - the string representing the table’s contents

  • :type - the type of offset (to be encoded in the ‘head’ table)



15
16
17
18
19
20
21
# File 'lib/ttfunk/table/loca.rb', line 15

def self.encode(offsets)
  if offsets.any? { |ofs| ofs > 0xFFFF }
    { :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) ⇒ Object



23
24
25
# File 'lib/ttfunk/table/loca.rb', line 23

def index_of(glyph_id)
  @offsets[glyph_id]
end

#size_of(glyph_id) ⇒ Object



27
28
29
# File 'lib/ttfunk/table/loca.rb', line 27

def size_of(glyph_id)
  @offsets[glyph_id+1] - @offsets[glyph_id]
end