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.

Experimental API 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, #bottom, #bottom_left, #bottom_right, #height, #reference_bounds, #stretchy?, #top, #top_left, #top_right

Constructor Details

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

:nodoc:



57
58
59
60
61
62
63
# File 'lib/prawn/document/column_box.rb', line 57

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

Instance Method Details

#add_left_padding(left_padding) ⇒ Object

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



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

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

#add_right_padding(right_padding) ⇒ Object



135
136
137
# File 'lib/prawn/document/column_box.rb', line 135

def add_right_padding(right_padding)
  @total_right_padding += right_padding
end

#bare_column_widthObject

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



67
68
69
# File 'lib/prawn/document/column_box.rb', line 67

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

#leftObject

Relative position of the left edge of the current column



92
93
94
# File 'lib/prawn/document/column_box.rb', line 92

def left
  width_of_column * @current_column
end

#left_sideObject

x coordinate of the left edge of the current column



86
87
88
# File 'lib/prawn/document/column_box.rb', line 86

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.



111
112
113
114
115
116
117
118
119
120
# File 'lib/prawn/document/column_box.rb', line 111

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

#rightObject

Relative position of the right edge of the current column.



105
106
107
# File 'lib/prawn/document/column_box.rb', line 105

def right
  left + width
end

#right_sideObject

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



98
99
100
101
# File 'lib/prawn/document/column_box.rb', line 98

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

#subtract_left_padding(left_padding) ⇒ Object



130
131
132
133
# File 'lib/prawn/document/column_box.rb', line 130

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

#subtract_right_padding(right_padding) ⇒ Object



139
140
141
# File 'lib/prawn/document/column_box.rb', line 139

def subtract_right_padding(right_padding)
  @total_right_padding -= right_padding
end

#widthObject

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



74
75
76
# File 'lib/prawn/document/column_box.rb', line 74

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

#width_of_columnObject

Column width including the spacer.



80
81
82
# File 'lib/prawn/document/column_box.rb', line 80

def width_of_column
  bare_column_width + @spacer
end