class AwesomeMapMarker::FontAwesome
Convert web-font to PNG
Public Class Methods
generate(type: :fas, name: 'map-marker', size: 128, fill_color: '
click to toggle source
# File lib/awesome_map_marker.rb, line 55 def generate(type: :fas, name: 'map-marker', size: 128, fill_color: '#FFFFFF') # MiniMagick.logger.level = Logger::DEBUG name.delete_prefix!('fa-') icon_data = icon_data(type.to_s, name.to_s) return nil if icon_data.nil? x = 0 y = 1 font_size = (size * 0.76).ceil unicode = icon_data[:unicode] char = [Integer("0x#{unicode}")].pack('U*') path = font_path(icon_type(type)) image = MiniMagick::Image.open( File.expand_path('../app/assets/images/base.png', __dir__) ) image.combine_options do |config| config.resize "#{size}x#{size}" config.font path config.gravity 'center' config.pointsize font_size config.kerning 0 config.stroke 'transparent' config.fill fill_color config.draw "text #{x},#{y} '#{char}'" end image end
icons(type)
click to toggle source
# File lib/awesome_map_marker.rb, line 91 def icons(type) icons_data_yml(icon_type(type).to_s) end
Private Class Methods
font_path(type)
click to toggle source
# File lib/awesome_map_marker.rb, line 124 def font_path(type) path = File.expand_path('../app/assets/fonts', __dir__) case icon_type(type).to_s when 'far' File.join(path, 'fa-regular-400.ttf') when 'fab' File.join(path, 'fa-brands-400.ttf') else # fas File.join(path, 'fa-solid-900.ttf') end end
icon_data(type, name)
click to toggle source
# File lib/awesome_map_marker.rb, line 97 def icon_data(type, name) icons_data_yml(icon_type(type).to_s).select do |icon| icon[:id] == name end.first end
icon_type(type)
click to toggle source
# File lib/awesome_map_marker.rb, line 103 def icon_type(type) return :fas if type.nil? case type.to_s when 'far', 'regular' :far when 'fab', 'brand' :fab else :fas end end
icons_data_yml(type)
click to toggle source
# File lib/awesome_map_marker.rb, line 116 def icons_data_yml(type) yml_path = File.expand_path( "../../config/#{icon_type(type)}.yml", __FILE__ ) YAML.load_file(yml_path) end