Class: TTFunk::SubTable

Inherits:
Object
  • Object
show all
Includes:
Reader
Defined in:
lib/ttfunk/sub_table.rb

Overview

SFNT sub-table

Defined Under Namespace

Classes: EOTError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, offset, length = nil) ⇒ SubTable

Returns a new instance of SubTable.

Parameters:

  • file (IO)
  • offset (Integer)
  • length (Integer) (defaults to: nil)


29
30
31
32
33
34
# File 'lib/ttfunk/sub_table.rb', line 29

def initialize(file, offset, length = nil)
  @file = file
  @table_offset = offset
  @length = length
  parse_from(@table_offset) { parse! }
end

Instance Attribute Details

#fileIO (readonly)

File or IO this sub-table is in.

Returns:

  • (IO)


16
17
18
# File 'lib/ttfunk/sub_table.rb', line 16

def file
  @file
end

#lengthInteger? (readonly)

This sub-table’s length in byes.

Returns:

  • (Integer, nil)


24
25
26
# File 'lib/ttfunk/sub_table.rb', line 24

def length
  @length
end

#table_offsetInteger (readonly)

This sub-table’s offset from the file beginning.

Returns:

  • (Integer)


20
21
22
# File 'lib/ttfunk/sub_table.rb', line 20

def table_offset
  @table_offset
end

Instance Method Details

#eot?Boolean

End of sub-table?

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/ttfunk/sub_table.rb', line 39

def eot?
  # if length isn't set yet there's no way to know if we're at the end of
  # the sub-table or not
  return false unless length

  io.pos > table_offset + length
end

#read(bytes, format) ⇒ Array

Read a series of values.

Parameters:

  • bytes (Integer)

    number of bytes to read.

  • format (String)

    format to parse the bytes.

Returns:

  • (Array)

Raises:

See Also:

  • Ruby Packed data


55
56
57
58
59
60
61
# File 'lib/ttfunk/sub_table.rb', line 55

def read(*args)
  if eot?
    raise EOTError, 'attempted to read past the end of the table'
  end

  super
end