Sha256: c6133026d2f492589da40c9638944d1f5eeef12d600e25d89957f386bfc0b0ac

Contents?: true

Size: 809 Bytes

Versions: 2

Compression:

Stored size: 809 Bytes

Contents

# frozen_string_literal: true

require_relative 'ttf'

module Prawn
  module Fonts
    # @private
    class TTC < TTF
      # Returns a list of the names of all named fonts in the given ttc file.
      # They are returned in order of their appearance in the file.
      #
      def self.font_names(file)
        TTFunk::Collection.open(file) do |ttc|
          ttc.map { |font| font.name.font_name.first }
        end
      end

      private

      def read_ttf_file
        TTFunk::File.from_ttc(
          @name,
          font_option_to_index(@name, @options[:font])
        )
      end

      def font_option_to_index(file, option)
        if option.is_a?(Numeric)
          option
        else
          self.class.font_names(file).index { |n| n == option } || 0
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prawn-2.4.0 lib/prawn/fonts/ttc.rb
prawn-2.3.0 lib/prawn/fonts/ttc.rb