Skip to content

Commit

Permalink
resolves prawnpdf#1022 provide more information about missing font
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mojavelinux committed Nov 8, 2017
1 parent 9250c86 commit 97a39c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/prawn/font/afm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ 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
Expand Down
8 changes: 8 additions & 0 deletions spec/prawn/font_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
end
end

it 'reports missing font with style' do
expect {
pdf.font('Nada', style: :bold) do
pdf.width_of('hello')
end
}.to raise_error(Prawn::Errors::UnknownFont, /Nada \(bold\)/)
end

it 'calculates styled widths correctly using TTFs' do
pdf.font_families.update(
'DejaVu Sans' => {
Expand Down

0 comments on commit 97a39c7

Please sign in to comment.