class Prawn::Icon::FontData
Attributes
set[R]
Public Class Methods
load(document, set)
click to toggle source
Font data lazy-loader that will initialize icon fonts by document.
# 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
new(document, opts = {})
click to toggle source
# File lib/prawn/icon/font_data.rb, line 47 def initialize(document, opts = {}) @set = opts[:set] || :fa load_fonts(document) end
release_data()
click to toggle source
Release all font references if requested.
# File lib/prawn/icon/font_data.rb, line 25 def release_data @data = {} end
specifier_from_key(key)
click to toggle 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
unicode_from_key(document, key)
click to toggle 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
font_version()
click to toggle source
# File lib/prawn/icon/font_data.rb, line 52 def font_version yaml[specifier]['__font_version__'] end
keys()
click to toggle source
# File lib/prawn/icon/font_data.rb, line 90 def keys # Strip the first element: __font_version__ yaml[specifier].keys.map { |k| "#{specifier}-#{k}" }.drop(1) end
legend_path()
click to toggle source
# File lib/prawn/icon/font_data.rb, line 56 def legend_path File.join(File.dirname(path), "#{@set}.yml") end
load_fonts(document)
click to toggle source
# File lib/prawn/icon/font_data.rb, line 60 def load_fonts(document) document.font_families[@set.to_s] ||= { normal: path } self end
path()
click to toggle source
# File lib/prawn/icon/font_data.rb, line 65 def path ttf = File.join(Icon::Base::FONTDIR, @set.to_s, '*.ttf') font = Dir[ttf].first if font.nil? raise Prawn::Errors::UnknownFont, "Icon font not found for set: #{@set}" end @path ||= font end
specifier()
click to toggle source
# File lib/prawn/icon/font_data.rb, line 77 def specifier @specifier ||= yaml.keys[0] end
unicode(key)
click to toggle source
# File lib/prawn/icon/font_data.rb, line 81 def unicode(key) yaml[specifier][key].tap do |char| unless char raise Errors::IconNotFound, "Key: #{specifier}-#{key} not found" end end end
yaml()
click to toggle source
# File lib/prawn/icon/font_data.rb, line 95 def yaml @yaml ||= YAML.load_file legend_path end