From 0752fdd9dca23597a00b221291de8945946c13f2 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 7 Nov 2017 23:54:06 -0700 Subject: [PATCH] resolves #1022 provide more information about missing font - when an afm font is missing, provide more information to the user - look for font name in family option in case of missing TTF - add test to confirm error is raised and message is correct --- lib/prawn/font/afm.rb | 4 +++- spec/prawn/font_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/prawn/font/afm.rb b/lib/prawn/font/afm.rb index 04c510e04..f32a62d7e 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' => {