Method: Prawn::Document#span

Defined in:
lib/prawn/document/span.rb

#span(width, options = {}) ⇒ Object

A span is a special purpose bounding box that allows a column of elements to be positioned relative to the margin_box.

Arguments:

width

The width of the column in PDF points

Options:

:position

One of :left, :center, :right or an x offset

This method is typically used for flowing a column of text from one page to the next.

span(350, :position => :center) do
  text "Here's some centered text in a 350 point column. " * 100
end


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/prawn/document/span.rb', line 27

def span(width, options={})
  Prawn.verify_options [:position], options
  original_position = self.y      
 
  # FIXME: Any way to move this upstream?
  left_boundary = case(options[:position] || :left)
  when :left
    margin_box.absolute_left
  when :center
    margin_box.absolute_left + margin_box.width / 2.0 - width /2.0
  when :right
    margin_box.absolute_right - width
  when Numeric
    margin_box.absolute_left + options[:position]
  else
    raise ArgumentError, "Invalid option for :position"
  end
  
  # we need to bust out of whatever nested bounding boxes we're in.
  canvas do
    bounding_box([left_boundary, 
                  margin_box.absolute_top], :width => width) do
      self.y = original_position
      yield
    end
  end          
end