Sha256: f373d0bb629a9bd0b3a54b3140bda39aaa64bb7c8071373d1a3cf786540179a9

Contents?: true

Size: 888 Bytes

Versions: 36

Compression:

Stored size: 888 Bytes

Contents

module TTFunk
  module Reader
    private

      def io
        @file.contents
      end

      def read(bytes, format)
        io.read(bytes).unpack(format)
      end

      def read_signed(count)
        read(count*2, "n*").map { |i| to_signed(i) }
      end

      def to_signed(n)
        (n>=0x8000) ? -((n ^ 0xFFFF) + 1) : n
      end

      def parse_from(position)
        saved, io.pos = io.pos, position
        result = yield position
        io.pos = saved
        return result
      end

      # For debugging purposes
      def hexdump(string)
        bytes = string.unpack("C*")
        bytes.each_with_index do |c, i|
          print "%02X" % c
          if (i+1) % 16 == 0
            puts
          elsif (i+1) % 8 == 0
            print "  "
          else
            print " "
          end
        end
        puts unless bytes.length % 16 == 0
      end
  end
end

Version data entries

36 entries across 36 versions & 10 rubygems

Version Path
ttfunk-1.4.0 lib/ttfunk/reader.rb
ttfunk-1.3.0 lib/ttfunk/reader.rb
ttfunk-1.2.2 lib/ttfunk/reader.rb
ttfunk-1.2.1 lib/ttfunk/reader.rb
ttfunk-1.2.0 lib/ttfunk/reader.rb
ttfunk-1.1.1 lib/ttfunk/reader.rb
ttfunk-1.1.0 lib/ttfunk/reader.rb
ttfunk-1.0.3 lib/ttfunk/reader.rb
ttfunk-1.0.2 lib/ttfunk/reader.rb
ttfunk-1.0.1 lib/ttfunk/reader.rb
davebenvenuti-prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/reader.rb
piglop-prawn-0.10.2.3 vendor/ttfunk/lib/ttfunk/reader.rb
piglop-prawn-0.10.2.2 vendor/ttfunk/lib/ttfunk/reader.rb
piglop-prawn-0.10.2.1 vendor/ttfunk/lib/ttfunk/reader.rb
glyph_imager-0.1.1 vendor/ttfunk/lib/ttfunk/reader.rb
prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/reader.rb
goodwill-prawn-edge-0.10.0 vendor/ttfunk/lib/ttfunk/reader.rb
alphasights-prawn-0.10.4 vendor/ttfunk/lib/ttfunk/reader.rb
alphasights-prawn-0.10.3 vendor/ttfunk/lib/ttfunk/reader.rb
alphasights-prawn-0.10.2 vendor/ttfunk/lib/ttfunk/reader.rb