# encoding: utf-8
#
# We've already seen one way of using text boxes with the text_box
# method. Turns out this method is just a convenience for using the
# Prawn::Text::Box
class as it creates a new object and call
# render
on it.
#
# Knowing that any extensions we add to Prawn::Text::Box
will take
# effect when we use the text_box
method. To add an extension all
# we need to do is append the Prawn::Text::Box.extensions
array
# with a module.
#
require File.expand_path(File.join(File.dirname(__FILE__),
%w[.. example_helper]))
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Example.generate(filename) do
module TriangleBox
def available_width
height + 25
end
end
y_position = cursor - 10
width = 100
height = 100
Prawn::Text::Box.extensions << TriangleBox
stroke_rectangle([0, y_position], width, height)
text_box("A" * 100,
:at => [0, y_position],
:width => width,
:height => height)
Prawn::Text::Formatted::Box.extensions << TriangleBox
stroke_rectangle([200, y_position], width, height)
formatted_text_box([:text => "A" * 100, :color => "009900"],
:at => [200, y_position],
:width => width,
:height => height)
# Here we clear the extensions array
Prawn::Text::Box.extensions.clear
Prawn::Text::Formatted::Box.extensions.clear
end