Sha256: 4d471b6560d694f2028b7da42bed288131248c1abf3a6758c843f74e71703436

Contents?: true

Size: 776 Bytes

Versions: 3

Compression:

Stored size: 776 Bytes

Contents

require_relative 'ttf'

module Prawn
  class Font
    # @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

3 entries across 3 versions & 1 rubygems

Version Path
prawn-2.2.2 lib/prawn/font/ttc.rb
prawn-2.2.1 lib/prawn/font/ttc.rb
prawn-2.2.0 lib/prawn/font/ttc.rb