Sha256: 75256039b3ae2ab61405f149826b6e2d26be12024474b3361c717e7c934fecaa

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

# encoding: utf-8

# span.rb : Implements text columns
#
# Copyright September 2008, Gregory Brown. All Rights Reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.

module Prawn
  class Document
    # 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:
    # <tt>:position</tt>:: 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
    #  
    def span(width, options={})
      Prawn.verify_options [:position], options
      original_position = self.y      
      
      # FIXME: How many effing times do I want to write this same code?
      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
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
kavu-prawn-core-0.4.100 lib/prawn/document/span.rb
kavu-prawn-core-0.4.99 lib/prawn/document/span.rb
prawn-layout-0.3.2 vendor/prawn-core/lib/prawn/document/span.rb
prawn-core-0.6.3 lib/prawn/document/span.rb
prawn-core-0.6.2 lib/prawn/document/span.rb
prawn-layout-0.3.1 vendor/prawn-core/lib/prawn/document/span.rb
prawn-core-0.6.1 lib/prawn/document/span.rb
prawn-core-0.5.1 lib/prawn/document/span.rb
prawn-core-0.5.0.1 lib/prawn/document/span.rb
prawn-0.3.0 lib/prawn/document/span.rb
prawn-0.4.0 lib/prawn/document/span.rb
prawn-0.4.1 lib/prawn/document/span.rb