Skip to content

Commit

Permalink
Thinreports raises Errors::UnknownFont when specified font family can…
Browse files Browse the repository at this point in the history
…'t be found
  • Loading branch information
hidakatsuya committed Jun 5, 2018
1 parent c148694 commit a74f612
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/thinreports/core/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def initialize(id, item_type = 'Basic')
end
end

class UnknownFont < Basic
# @param [Prawn::Errors::UnknownFont] exception
def initialize(exception)
super("#{exception.class}: #{exception.message}")
end
end

class DisabledListSection < Basic
def initialize(section)
super("The #{section} section is disabled.")
Expand Down
4 changes: 3 additions & 1 deletion lib/thinreports/generator/pdf/document/graphics/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Graphics
# @option attrs [Boolean] :single (false)
# @option attrs [:trancate, :shrink_to_fit, :expand] :overflow (:trancate)
# @option attrs [:none, :break_word] :word_wrap (:none)
# @raise [Thinreports::Errors::UnknownFont] When :font can't be found in built-in fonts and registerd fonts
def text_box(content, x, y, w, h, attrs = {})

return if attrs[:color] == 'none'
Expand All @@ -40,7 +41,8 @@ def text_box(content, x, y, w, h, attrs = {})
else
pdf.formatted_text_box([text_params], box_params)
end

rescue Prawn::Errors::UnknownFont => e
raise Thinreports::Errors::UnknownFont, e
rescue Prawn::Errors::CannotFit
# Nothing to do.
#
Expand Down

0 comments on commit a74f612

Please sign in to comment.