lib/prawn/text/box.rb in prawn-0.12.0 vs lib/prawn/text/box.rb in prawn-0.13.0
- old
+ new
@@ -5,28 +5,30 @@
# Copyright November 2009, Daniel Nelson. All Rights Reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
#
+require_relative "formatted/box"
+
module Prawn
module Text
# Draws the requested text into a box. When the text overflows
# the rectangle, you shrink to fit, or truncate the text. Text
# boxes are independent of the document y position.
#
# == Encoding
#
# Note that strings passed to this function should be encoded as UTF-8.
- # If you get unexpected characters appearing in your rendered document,
+ # If you get unexpected characters appearing in your rendered document,
# check this.
#
# If the current font is a built-in one, although the string must be
# encoded as UTF-8, only characters that are available in WinAnsi
# are allowed.
#
- # If an empty box is rendered to your PDF instead of the character you
+ # If an empty box is rendered to your PDF instead of the character you
# wanted it usually means the current font doesn't include that character.
#
# == Options (default values marked in [])
#
# <tt>:kerning</tt>:: <tt>boolean</tt>. Whether or not to use kerning (if it
@@ -65,11 +67,11 @@
# <tt>:justify</tt> Alignment within the bounding box
# [:left if direction is :ltr, :right if direction is :rtl]
# <tt>:valign</tt>::
# <tt>:top</tt>, <tt>:center</tt>, or <tt>:bottom</tt>. Vertical
# alignment within the bounding box [:top]
- #
+ #
# <tt>:rotate</tt>::
# <tt>number</tt>. The angle to rotate the text
# <tt>:rotate_around</tt>::
# <tt>:center</tt>, <tt>:upper_left</tt>, <tt>:upper_right</tt>,
# <tt>:lower_right</tt>, or <tt>:lower_left</tt>. The point around which
@@ -103,14 +105,25 @@
#
# Raises <tt>Prawn::Errrors::CannotFit</tt> if not wide enough to print
# any text
#
def text_box(string, options={})
- Text::Box.new(string, options.merge(:document => self)).render
+ options = options.dup
+ options[:document] = self
+
+ box = if p = options.delete(:inline_format)
+ p = [] unless p.is_a?(Array)
+ array = self.text_formatter.format(string, *p)
+ Text::Formatted::Box.new(array, options)
+ else
+ Text::Box.new(string, options)
+ end
+
+ box.render
end
# Generally, one would use the Prawn::Text#text_box convenience
- # method. However, using Text::Box.new in conjunction with
+ # method. However, using Text::Box.new in conjunction with
# #render(:dry_run=> true) enables one to do look-ahead calculations prior
# to placing text on the page, or to determine how much vertical space was
# consumed by the printed text
#
class Box < Prawn::Text::Formatted::Box