@@ -23,9 +23,11 @@ module Font
2323 def setup_fonts
2424 # Install built-in fonts.
2525 BUILTIN_FONTS . each do |font_name , font_path |
26- install_font ( font_name , font_path )
26+ install_font ( font_name , normal : font_path )
2727 end
2828
29+ install_custom_fonts
30+
2931 # Create aliases from the font list provided by Prawn.
3032 PRAWN_BUINTIN_FONT_ALIASES . each do |alias_name , name |
3133 pdf . font_families [ alias_name ] = pdf . font_families [ name ]
@@ -37,7 +39,7 @@ def setup_fonts
3739 if pdf . font_families . key? ( font )
3840 font
3941 else
40- install_font "Custom-fallback-font#{ i } " , font
42+ install_font "Custom-fallback-font#{ i } " , normal : font
4143 end
4244 end
4345
@@ -46,20 +48,32 @@ def setup_fonts
4648 end
4749
4850 # @param [String] name
49- # @param [String] file
51+ # @param [String] normal (required) Path for normal style font
52+ # @param [String] bold Path for bold style font. Set :normal by default.
53+ # @param [String] italic Path for italic style font. Set :normal by default.
54+ # @param [String] bold_italic Path for bold+italic style font. Set :normal by default.
55+ # @raise [Thinreports::Errors::FontFileNotFound]
5056 # @return [String] installed font name
51- def install_font ( name , file )
52- raise Errors ::FontFileNotFound unless File . exist? ( file )
57+ def install_font ( name , normal :, bold : normal , italic : normal , bold_italic : normal )
58+ [ normal , bold , italic , bold_italic ] . uniq . each do |font_file |
59+ raise Thinreports ::Errors ::FontFileNotFound , font_file unless File . exist? ( font_file )
60+ end
5361
5462 pdf . font_families [ name ] = {
55- normal : file ,
56- bold : file ,
57- italic : file ,
58- bold_italic : file
63+ normal : normal ,
64+ bold : bold ,
65+ italic : italic ,
66+ bold_italic : bold_italic
5967 }
6068 name
6169 end
6270
71+ def install_custom_fonts
72+ Thinreports . config . fonts . each do |font_name , font_paths |
73+ install_font ( font_name , **font_paths )
74+ end
75+ end
76+
6377 # @return [String]
6478 def default_family
6579 'Helvetica'
0 commit comments