Class: TTFunk::Table::Loca

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

Overview

Index to Location table.

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

#offsetsArray<Integer> (readonly)

Glyph ofsets

Returns:

  • (Array<Integer>)


11
12
13
# File 'lib/ttfunk/table/loca.rb', line 11

def offsets
  @offsets
end

Class Method Details

.encode(offsets) ⇒ Hash

Encode table.

Parameters:

  • offsets (Array<Integer>)

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

Returns:

  • (Hash)

    result hash:

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

      • ‘0` - short offsets

      • ‘1` - long offsets

    • ‘:table` - encoded bytes



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.

Parameters:

  • glyph_id (Integer)

Returns:

  • (Integer)
    • offset of the glyph in the ‘glyf` table



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.

Parameters:

  • glyph_id (Integer)

Returns:

  • (Integer)


48
49
50
# File 'lib/ttfunk/table/loca.rb', line 48

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