class TTFunk::Table::Loca
Attributes
offsets[R]
Public Class Methods
encode(offsets)
click to toggle source
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)
# File lib/ttfunk/table/loca.rb, line 17 def self.encode(offsets) long_offsets = offsets.any? do |offset| short_offset = offset / 2 short_offset * 2 != offset || short_offset > 0xffff end if long_offsets { type: 1, table: offsets.pack('N*') } else { type: 0, table: offsets.map { |o| o / 2 }.pack('n*') } end end
Public Instance Methods
index_of(glyph_id)
click to toggle source
# File lib/ttfunk/table/loca.rb, line 31 def index_of(glyph_id) @offsets[glyph_id] end
size_of(glyph_id)
click to toggle source
# File lib/ttfunk/table/loca.rb, line 35 def size_of(glyph_id) @offsets[glyph_id + 1] - @offsets[glyph_id] end
Private Instance Methods
parse!()
click to toggle source
# File lib/ttfunk/table/loca.rb, line 41 def parse! type = file.header.index_to_loc_format.zero? ? 'n' : 'N' @offsets = read(length, "#{type}*") if file.header.index_to_loc_format.zero? @offsets.map! { |v| v * 2 } end end