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>)
Source Code
lib/ttfunk/table/loca.rb, line 11
11
def offsets
12
  @offsets
13
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
Source Code
lib/ttfunk/table/loca.rb, line 22
22
def self.encode(offsets)
23
  long_offsets =
24
    offsets.any? { |offset|
25
      short_offset = offset / 2
26
      short_offset * 2 != offset || short_offset > 0xffff
27
    }
28
29
  if long_offsets
30
    { type: 1, table: offsets.pack('N*') }
31
  else
32
    { type: 0, table: offsets.map { |o| o / 2 }.pack('n*') }
33
  end
34
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
Source Code
lib/ttfunk/table/loca.rb, line 40
40
def index_of(glyph_id)
41
  @offsets[glyph_id]
42
end

#size_of(glyph_id) ⇒ Integer

Size of encoded glyph.

Parameters:

  • glyph_id (Integer)

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/loca.rb, line 48
48
def size_of(glyph_id)
49
  @offsets[glyph_id + 1] - @offsets[glyph_id]
50
end