Sha256: 5c89a3e18b67653a68add67009143cff755de10194e58a69697fccd4c89dc92c

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module TTFunk
  class Table
    class Cff < TTFunk::Table
      # CFF Index with indexing starting at 1.
      class OneBasedIndex
        extend Forwardable

        def_delegators :base_index,
          :each,
          :table_offset,
          :items_count,
          :length,
          :encode

        # Underlaying Index.
        # @return [TTFunk::Table::Cff::Index]
        attr_reader :base_index

        # @param args [Array] all params are passed to the base index.
        # @see Index
        def initialize(*args)
          @base_index = Index.new(*args)
        end

        # Get item by index.
        #
        # @param idx [Integer]
        # @return [any]
        # @raise [IndexError] when requested index is 0.
        def [](idx)
          if idx.zero?
            raise IndexError,
              "index #{idx} was outside the bounds of the index"
          end

          base_index[idx - 1]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ttfunk-1.8.0 lib/ttfunk/table/cff/one_based_index.rb