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, #anchor, #bottom, #bottom_left, #bottom_right, #deep_copy, #height, #indent, #reference_bounds, restore_deep_copy, #stretchy?, #top, #top_left, #top_right

Constructor Details

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

: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

- (Object) add_left_padding(left_padding)

Override the padding functions so as not to split the padding amount between all columns on the page.



113
114
115
116
# File 'lib/prawn/document/column_box.rb', line 113

def add_left_padding(left_padding)
  @total_left_padding += left_padding
  @x += left_padding
end

- (Object) add_right_padding(right_padding)



123
124
125
# File 'lib/prawn/document/column_box.rb', line 123

def add_right_padding(right_padding)
  @total_right_padding += right_padding
end

- (Object) bare_column_width

The column width, not the width of the whole box, before left and/or right padding



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

def bare_column_width
  (@width - @spacer * (@columns - 1)) / @columns
end

- (Object) left

Relative position of the left edge of the current column



83
84
85
# File 'lib/prawn/document/column_box.rb', line 83

def left
  width_of_column * @current_column
end

- (Object) left_side

x coordinate of the left edge of the current column



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

def left_side
  absolute_left + (width_of_column * @current_column)
end

- (Object) move_past_bottom

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



102
103
104
105
106
107
108
# File 'lib/prawn/document/column_box.rb', line 102

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

- (Object) right

Relative position of the right edge of the current column.



96
97
98
# File 'lib/prawn/document/column_box.rb', line 96

def right
  left + width
end

- (Object) right_side

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



89
90
91
92
# File 'lib/prawn/document/column_box.rb', line 89

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

- (Object) subtract_left_padding(left_padding)



118
119
120
121
# File 'lib/prawn/document/column_box.rb', line 118

def subtract_left_padding(left_padding)
  @total_left_padding -= left_padding
  @x -= left_padding
end

- (Object) subtract_right_padding(right_padding)



127
128
129
# File 'lib/prawn/document/column_box.rb', line 127

def subtract_right_padding(right_padding)
  @total_right_padding -= right_padding
end

- (Object) width

The column width after padding. Used to calculate how long a line of text can be.



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

def width
  bare_column_width - (@total_left_padding + @total_right_padding)
end

- (Object) width_of_column

Column width including the spacer.



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

def width_of_column
  bare_column_width + @spacer
end