lib/thinreports/generator/pdf/document/graphics/text.rb in thinreports-0.11.0 vs lib/thinreports/generator/pdf/document/graphics/text.rb in thinreports-0.12.0
- old
+ new
@@ -20,11 +20,11 @@
# @option attrs [Numeric, String] :line_height The total height of an text line.
# @option attrs [Numeric, String] :letter_spacing
# @option attrs [Boolean] :single (false)
# @option attrs [:trancate, :shrink_to_fit, :expand] :overflow (:trancate)
# @option attrs [:none, :break_word] :word_wrap (:none)
- def text_box(content, x, y, w, h, attrs = {})
+ def text_box(content, x, y, w, h, attrs = {}, &block)
w, h = s2f(w, h)
box_attrs = text_box_attrs(
x, y, w, h,
single: attrs.delete(:single),
@@ -33,13 +33,18 @@
# Do not break by word unless :word_wrap is :break_word
content = text_without_line_wrap(content) if attrs[:word_wrap] == :none
with_text_styles(attrs) do |built_attrs, font_styles|
- pdf.formatted_text_box(
- [{ text: content, styles: font_styles }],
- built_attrs.merge(box_attrs)
- )
+ if block
+ block.call [{ text: content, styles: font_styles }],
+ built_attrs.merge(box_attrs)
+ else
+ pdf.formatted_text_box(
+ [{ text: content, styles: font_styles }],
+ built_attrs.merge(box_attrs)
+ )
+ end
end
rescue Prawn::Errors::CannotFit
# Nothing to do.
#
# When the area is too small compared