class TTFunk::Table::Loca
Index to Location table.
Attributes
Glyph ofsets @return [Array<Integer>]
Public Class Methods
Source
# 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
Encode table.
@param offsets [Array<Integer>] an array of offsets, with each index
corresponding to the glyph id with that index.
@return [Hash] result hash:
* `:type` - the type of offset (to be encoded in the 'head' table): * `0` - short offsets * `1` - long offsets * `:table` - encoded bytes
Public Instance Methods
Source
# File lib/ttfunk/table/loca.rb, line 40 def index_of(glyph_id) @offsets[glyph_id] end
Glyph offset by ID.
@param glyph_id [Integer] @return [Integer] - offset of the glyph in the ‘glyf` table
Source
# File lib/ttfunk/table/loca.rb, line 48 def size_of(glyph_id) @offsets[glyph_id + 1] - @offsets[glyph_id] end
Size of encoded glyph.
@param glyph_id [Integer] @return [Integer]
Private Instance Methods
Source
# File lib/ttfunk/table/loca.rb, line 54 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