Sha256: 7a95882c2dec048dd47b74e8934963a6d8150039aec9d61003f80899b472d2c1

Contents?: true

Size: 964 Bytes

Versions: 4

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

module TTFunk
  class Table
    class Cmap < Table
      attr_reader :version
      attr_reader :tables

      def self.encode(charmap, encoding)
        result = Cmap::Subtable.encode(charmap, encoding)

        # pack 'version' and 'table-count'
        result[:table] = [0, 1, result.delete(:subtable)].pack('nnA*')
        result
      end

      def unicode
        # Because most callers just call .first on the result, put tables with
        # highest-number format first. Unsupported formats will be ignored.
        @unicode ||= @tables
                     .select { |table| table.unicode? && table.supported? }
                     .sort { |a, b| b.format <=> a.format }
      end

      private

      def parse!
        @version, table_count = read(4, 'nn')
        @tables = Array.new(table_count) do
          Cmap::Subtable.new(file, offset)
        end
      end
    end
  end
end

require_relative 'cmap/subtable'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ttfunk-1.6.2.1 lib/ttfunk/table/cmap.rb
ttfunk-1.6.2 lib/ttfunk/table/cmap.rb
ttfunk-1.6.1 lib/ttfunk/table/cmap.rb
ttfunk-1.6.0 lib/ttfunk/table/cmap.rb