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)
Source Code
lib/ttfunk/sub_table.rb, line 29
29
def initialize(file, offset, length = nil)
30
  @file = file
31
  @table_offset = offset
32
  @length = length
33
  parse_from(@table_offset) { parse! }
34
end

Instance Attribute Details

#fileIO (readonly)

File or IO this sub-table is in.

Returns:

  • (IO)
Source Code
lib/ttfunk/sub_table.rb, line 16
16
def file
17
  @file
18
end

#lengthInteger? (readonly)

This sub-table’s length in byes.

Returns:

  • (Integer, nil)
Source Code
lib/ttfunk/sub_table.rb, line 24
24
def length
25
  @length
26
end

#table_offsetInteger (readonly)

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

Returns:

  • (Integer)
Source Code
lib/ttfunk/sub_table.rb, line 20
20
def table_offset
21
  @table_offset
22
end

Instance Method Details

#eot?Boolean

End of sub-table?

Returns:

  • (Boolean)
Source Code
lib/ttfunk/sub_table.rb, line 39
39
def eot?
40
  # if length isn't set yet there's no way to know if we're at the end of
41
  # the sub-table or not
42
  return false unless length
43
44
  io.pos > table_offset + length
45
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
Source Code
lib/ttfunk/sub_table.rb, line 55
55
def read(*args)
56
  if eot?
57
    raise EOTError, 'attempted to read past the end of the table'
58
  end
59
60
  super
61
end