module TTFunk::Reader

Private Instance Methods

hexdump(string) click to toggle source

For debugging purposes

# File lib/ttfunk/reader.rb, line 32
def hexdump(string)
  bytes = string.unpack('C*')
  bytes.each_with_index do |c, i|
    printf('%02X', c)
    if ((i + 1) % 16).zero?
      puts
    elsif ((i + 1) % 8).zero?
      print '  '
    else
      print ' '
    end
  end
  puts unless (bytes.length % 16).zero?
end
io() click to toggle source
# File lib/ttfunk/reader.rb, line 7
def io
  @file.contents
end
parse_from(position) { |position| ... } click to toggle source
# File lib/ttfunk/reader.rb, line 23
def parse_from(position)
  saved = io.pos
  io.pos = position
  result = yield position
  io.pos = saved
  result
end
read(bytes, format) click to toggle source
# File lib/ttfunk/reader.rb, line 11
def read(bytes, format)
  io.read(bytes).unpack(format)
end
read_signed(count) click to toggle source
# File lib/ttfunk/reader.rb, line 15
def read_signed(count)
  read(count * 2, 'n*').map { |i| to_signed(i) }
end
to_signed(number) click to toggle source
# File lib/ttfunk/reader.rb, line 19
def to_signed(number)
  number >= 0x8000 ? -((number ^ 0xFFFF) + 1) : number
end