class Prawn::Icon::FontData
Attributes
Public Class Methods
Source
# File lib/prawn/icon/font_data.rb, line 17 def load(document, set) set = set.to_sym @data ||= {} @data[set] ||= FontData.new(document, set: set) @data[set].load_fonts(document) end
Font data lazy-loader that will initialize icon fonts by document.
Source
# File lib/prawn/icon/font_data.rb, line 47 def initialize(document, opts = {}) @set = opts.fetch(:set) load_fonts(document) end
Source
# File lib/prawn/icon/font_data.rb, line 25 def release_data @data = {} end
Release all font references if requested.
Source
# File lib/prawn/icon/font_data.rb, line 35 def specifier_from_key(key) if key.nil? || key == '' raise Errors::IconKeyEmpty, 'Icon key provided was nil.' end key.split('-')[0].to_sym end
Source
# File lib/prawn/icon/font_data.rb, line 29 def unicode_from_key(document, key) set = specifier_from_key(key) key = key.sub(Regexp.new("#{set}-"), '') load(document, set).unicode(key) end
Public Instance Methods
Source
# File lib/prawn/icon/font_data.rb, line 52 def font_version yaml[specifier]['__font_version__'] end
Source
# File lib/prawn/icon/font_data.rb, line 94 def keys # Strip the first element: __font_version__ yaml[specifier].keys.map { |k| "#{specifier}-#{k}" }.drop(1) end
Source
# File lib/prawn/icon/font_data.rb, line 56 def legend_path File.join(File.dirname(path), "#{@set}.yml") end
Source
# File lib/prawn/icon/font_data.rb, line 60 def load_fonts(document) document.font_families[@set.to_s] ||= { normal: path } self end
Source
# File lib/prawn/icon/font_data.rb, line 65 def path @path = begin font = Icon.configuration.font_directory .join(@set.to_s) .glob('*.ttf') .first if font.nil? raise Prawn::Errors::UnknownFont, "Icon font not found for set: #{@set}" end font.to_s end end
Source
# File lib/prawn/icon/font_data.rb, line 81 def specifier @specifier ||= yaml.keys[0] end
Source
# File lib/prawn/icon/font_data.rb, line 85 def unicode(key) yaml[specifier][key].tap do |char| unless char raise Errors::IconNotFound, "Key: #{specifier}-#{key} not found" end end end
Source
# File lib/prawn/icon/font_data.rb, line 99 def yaml @yaml ||= YAML.load_file legend_path end