Class: Prawn::Document::ColumnBox

Inherits:
BoundingBox show all
Defined in:
lib/prawn/document/column_box.rb

Overview

Implements the necessary functionality to allow Document#column_box to work.

Instance Attribute Summary

Attributes inherited from BoundingBox

#document, #parent, #total_left_padding, #total_right_padding

Instance Method Summary collapse

Methods inherited from BoundingBox

#absolute_bottom, #absolute_bottom_left, #absolute_bottom_right, #absolute_left, #absolute_right, #absolute_top, #absolute_top_left, #absolute_top_right, #add_left_padding, #add_right_padding, #anchor, #bottom, #bottom_left, #bottom_right, #deep_copy, #height, #indent, #left, #reference_bounds, restore_deep_copy, #right, #stretchy?, #subtract_left_padding, #subtract_right_padding, #top, #top_left, #top_right

Constructor Details

#initialize(document, parent, point, options = {}) ⇒ ColumnBox

:nodoc:



49
50
51
52
53
54
# File 'lib/prawn/document/column_box.rb', line 49

def initialize(document, parent, point, options={}) #:nodoc:
  super
  @columns = options[:columns] || 3
  @spacer  = options[:spacer]  || @document.font_size
  @current_column = 0
end

Instance Method Details

#left_sideObject

x coordinate of the left edge of the current column



71
72
73
# File 'lib/prawn/document/column_box.rb', line 71

def left_side
  absolute_left + (width_of_column * @current_column)
end

#move_past_bottomObject

Moves to the next column or starts a new page if currently positioned at the rightmost column.



84
85
86
87
88
89
90
# File 'lib/prawn/document/column_box.rb', line 84

def move_past_bottom 
  @current_column = (@current_column + 1) % @columns
  @document.y = @y
  if 0 == @current_column
    @document.start_new_page
  end
end

#right_sideObject

x co-orordinate of the right edge of the current column



77
78
79
80
# File 'lib/prawn/document/column_box.rb', line 77

def right_side
  columns_from_right = @columns - (1 + @current_column)
  absolute_right - (width_of_column * columns_from_right)
end

#widthObject

The column width, not the width of the whole box. Used to calculate how long a line of text can be.



59
60
61
# File 'lib/prawn/document/column_box.rb', line 59

def width
  super / @columns - @spacer
end

#width_of_columnObject

Column width including the spacer.



65
66
67
# File 'lib/prawn/document/column_box.rb', line 65

def width_of_column
  width + @spacer
end