module Thinreports::Generator::PDF::Font
Constants
- BUILTIN_FONTS
- DEFAULT_FALLBACK_FONTS
- FONT_STORE
- PRAWN_BUINTIN_FONT_ALIASES
Public Instance Methods
default_family()
click to toggle source
@return [String]
# File lib/thinreports/generator/pdf/document/font.rb, line 64 def default_family 'Helvetica' end
default_family_if_missing(family)
click to toggle source
@param [String] family @return [String]
# File lib/thinreports/generator/pdf/document/font.rb, line 70 def default_family_if_missing(family) pdf.font_families.key?(family) ? family : default_family end
font_has_style?(font_name, font_style)
click to toggle source
@param [String] font_name @param [:bold, :italic] font_style @return [Boolean]
# File lib/thinreports/generator/pdf/document/font.rb, line 77 def font_has_style?(font_name, font_style) font = pdf.font_families[font_name] return false unless font return false unless font.key?(font_style) font[font_style] != font[:normal] end
install_font(name, file)
click to toggle source
@param [String] name @param [String] file @return [String] installed font name
# File lib/thinreports/generator/pdf/document/font.rb, line 51 def install_font(name, file) raise Errors::FontFileNotFound unless File.exist?(file) pdf.font_families[name] = { normal: file, bold: file, italic: file, bold_italic: file } name end
setup_fonts()
click to toggle source
# File lib/thinreports/generator/pdf/document/font.rb, line 23 def setup_fonts # Install built-in fonts. BUILTIN_FONTS.each do |font_name, font_path| install_font(font_name, font_path) end # Create aliases from the font list provided by Prawn. PRAWN_BUINTIN_FONT_ALIASES.each do |alias_name, name| pdf.font_families[alias_name] = pdf.font_families[name] end # Setup custom fallback fonts fallback_fonts = Thinreports.config.fallback_fonts.uniq fallback_fonts.map!.with_index do |font, i| if pdf.font_families.key?(font) font else install_font "Custom-fallback-font#{i}", font end end # Set fallback fonts pdf.fallback_fonts(fallback_fonts + DEFAULT_FALLBACK_FONTS) end