module TTFunk::Reader
Helper methods to read form file content. @api rpivate
Private Instance Methods
Source
# File lib/ttfunk/reader.rb, line 34 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 if (bytes.length % 16) != 0 end
For debugging purposes
Source
# File lib/ttfunk/reader.rb, line 25 def parse_from(position) saved = io.pos io.pos = position result = yield(position) io.pos = saved result end
Source
# File lib/ttfunk/reader.rb, line 13 def read(bytes, format) io.read(bytes).unpack(format) end
Source
# File lib/ttfunk/reader.rb, line 17 def read_signed(count) read(count * 2, 'n*').map { |i| to_signed(i) } end
Source
# File lib/ttfunk/reader.rb, line 21 def to_signed(number) number >= 0x8000 ? -((number ^ 0xFFFF) + 1) : number end