diff --git a/lib/prawn/font/afm.rb b/lib/prawn/font/afm.rb index 04c510e04..1ffc3fe60 100644 --- a/lib/prawn/font/afm.rb +++ b/lib/prawn/font/afm.rb @@ -49,8 +49,10 @@ def self.font_data end def initialize(document, name, options = {}) #:nodoc: + name ||= options[:family] unless BUILT_INS.include?(name) - raise Prawn::Errors::UnknownFont, "#{name} is not a known font." + raise Prawn::Errors::UnknownFont, + "#{name} (#{options[:style] || 'normal'}) is not a known font." end super diff --git a/spec/prawn/font_spec.rb b/spec/prawn/font_spec.rb index 922479f4f..ca1ae2872 100644 --- a/spec/prawn/font_spec.rb +++ b/spec/prawn/font_spec.rb @@ -69,6 +69,14 @@ end end + it 'reports missing font with style' do + expect do + pdf.font('Nada', style: :bold) do + pdf.width_of('hello') + end + end.to raise_error(Prawn::Errors::UnknownFont, /Nada \(bold\)/) + end + it 'calculates styled widths correctly using TTFs' do pdf.font_families.update( 'DejaVu Sans' => {