Sha256: 69ab54ff45b505a1781672e84f532c93494bfc2556e54b32657065afd5df6e5b

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_relative 'ttf'

module Prawn
  module Fonts
    # DFONT font. DFONT is a bunch of TrueType fonts in a single file.
    #
    # @note You shouldn't use this class directly.
    class DFont < TTF
      # Returns a list of the names of all named fonts in the given dfont file.
      # Note that fonts are not required to be named in a dfont file, so the
      # list may be empty even if the file does contain fonts. Also, note that
      # the list is returned in no particular order, so the first font in the
      # list is not necessarily the font at index 0 in the file.
      #
      # @param file [String]
      # @return [Array<String>]
      def self.named_fonts(file)
        TTFunk::ResourceFile.open(file) do |f|
          return f.resources_for('sfnt')
        end
      end

      # Returns the number of fonts contained in the dfont file.
      #
      # @param file [String]
      # @return [Integer]
      def self.font_count(file)
        TTFunk::ResourceFile.open(file) do |f|
          return f.map['sfnt'][:list].length
        end
      end

      private

      def read_ttf_file
        TTFunk::File.from_dfont(@name, @options[:font] || 0)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prawn-2.5.0 lib/prawn/fonts/dfont.rb