Object
# File lib/prawn/svg/font.rb, line 56 def self.correctly_cased_font_name(name) @font_case_mapping[name.downcase] end
# File lib/prawn/svg/font.rb, line 52 def self.installed_fonts @installed_fonts end
# File lib/prawn/svg/font.rb, line 11 def self.load(family, weight = nil, style = nil) family.split(",").detect do |name| name = name.gsub(/['"]/, '').gsub(/\s{2,}/, ' ').strip.downcase # If it's a standard CSS font name, map it to one of the standard PDF fonts. name = GENERIC_CSS_FONT_MAPPING[name] || name font = new(name, weight, style) break font if font.installed? end end
This method is passed prawn’s font_families hash. It’ll be pre-populated with the fonts that prawn natively supports. We’ll add fonts we find in the font path to this hash.
# File lib/prawn/svg/font.rb, line 36 def self.load_external_fonts(fonts) Prawn::Svg::Interface.font_path.uniq.collect {|path| Dir["#{path}/**/*"]}.flatten.each do |filename| information = font_information(filename) rescue nil if information && font_name = (information[16] || information[1]) subfamily = (information[17] || information[2] || "normal").gsub(/\s+/, "_").downcase.to_sym subfamily = :normal if subfamily == :regular (fonts[font_name] ||= {})[subfamily] = filename end end @font_case_mapping = {} fonts.each {|key, _| @font_case_mapping[key.downcase] = key} @installed_fonts = fonts end
# File lib/prawn/svg/font.rb, line 61 def initialize(name, weight, style) @name = self.class.correctly_cased_font_name(name) || name @weight = weight @style = style end
# File lib/prawn/svg/font.rb, line 23 def self.weight_for_css_font_weight(weight) case weight when '100', '200', '300' then :light when '400', '500' then :normal when '600' then :semibold when '700', 'bold' then :bold when '800' then :extrabold when '900' then :black end end
# File lib/prawn/svg/font.rb, line 67 def installed? subfamilies = self.class.installed_fonts[name] !subfamilies.nil? && subfamilies.key?(subfamily) end
Construct a subfamily name, ensuring that the subfamily is a valid one for the font.
# File lib/prawn/svg/font.rb, line 73 def subfamily if subfamilies = self.class.installed_fonts[name] if subfamilies.key?(subfamily_name) subfamily_name elsif subfamilies.key?(:normal) :normal else subfamilies.keys.first end end end
Generated with the Darkfish Rdoc Generator 2.