File: dfont.rb

package info (click to toggle)
ruby-prawn 2.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,320 kB
  • sloc: ruby: 15,654; sh: 43; makefile: 20
file content (34 lines) | stat: -rw-r--r-- 966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require_relative 'ttf'

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