From a74f612dfaf302f0945d75e10ecd5054acf283b8 Mon Sep 17 00:00:00 2001 From: Katsuya HIDAKA Date: Sun, 18 Mar 2018 21:48:12 +0900 Subject: [PATCH] Thinreports raises Errors::UnknownFont when specified font family can't be found --- lib/thinreports/core/errors.rb | 7 +++++++ lib/thinreports/generator/pdf/document/graphics/text.rb | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/thinreports/core/errors.rb b/lib/thinreports/core/errors.rb index db121737..d52676a5 100644 --- a/lib/thinreports/core/errors.rb +++ b/lib/thinreports/core/errors.rb @@ -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.") diff --git a/lib/thinreports/generator/pdf/document/graphics/text.rb b/lib/thinreports/generator/pdf/document/graphics/text.rb index 5bb2024f..2ab269d8 100644 --- a/lib/thinreports/generator/pdf/document/graphics/text.rb +++ b/lib/thinreports/generator/pdf/document/graphics/text.rb @@ -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' @@ -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. #