Sha256: 537e28c7702cc07db812fadd029b271317011f40b7534e5ad7fa7e68085d4164

Contents?: true

Size: 732 Bytes

Versions: 5

Compression:

Stored size: 732 Bytes

Contents

# frozen_string_literal: true

require_relative './reader'

module TTFunk
  class SubTable
    class EOTError < StandardError
    end

    include Reader

    attr_reader :file, :table_offset, :length

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

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

      io.pos > table_offset + length
    end

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

      super
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ttfunk-1.7.0 lib/ttfunk/sub_table.rb
ttfunk-1.6.2.1 lib/ttfunk/sub_table.rb
ttfunk-1.6.2 lib/ttfunk/sub_table.rb
ttfunk-1.6.1 lib/ttfunk/sub_table.rb
ttfunk-1.6.0 lib/ttfunk/sub_table.rb