Class: Prawn::Document::Box
- Inherits:
-
Object
- Object
- Prawn::Document::Box
- Defined in:
- lib/prawn/layout/grid.rb
Overview
A Box is a class that represents a bounded area of a page.
A Grid object has methods that allow easy access to the coordinates of its corners, which can be plugged into most existing prawnmethods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
Instance Method Summary collapse
-
#bottom ⇒ Object
y-coordinate of the bottom.
-
#bottom_left ⇒ Object
x,y coordinates of bottom left corner.
-
#bottom_right ⇒ Object
x,y coordinates of bottom right corner.
-
#bounding_box(&blk) ⇒ Object
Creates a standard bounding box based on the grid box.
-
#gutter ⇒ Object
Width of the gutter.
-
#height ⇒ Object
Height of a box.
-
#initialize(pdf, i, j) ⇒ Box
constructor
A new instance of Box.
-
#left ⇒ Object
x-coordinate of left side.
-
#name ⇒ Object
Mostly diagnostic method that outputs the name of a box as col_num, row_num.
-
#right ⇒ Object
x-coordinate of right side.
-
#show(grid_color = "CCCCCC") ⇒ Object
Diagnostic method.
-
#top ⇒ Object
y-coordinate of the top.
-
#top_left ⇒ Object
x,y coordinates of top left corner.
-
#top_right ⇒ Object
x,y coordinates of top right corner.
-
#total_height ⇒ Object
:nodoc.
-
#width ⇒ Object
Width of a box.
Constructor Details
#initialize(pdf, i, j) ⇒ Box
Returns a new instance of Box.
93 94 95 96 97 |
# File 'lib/prawn/layout/grid.rb', line 93 def initialize(pdf, i, j) @pdf = pdf @i = i @j = j end |
Instance Attribute Details
#pdf ⇒ Object (readonly)
Returns the value of attribute pdf.
91 92 93 |
# File 'lib/prawn/layout/grid.rb', line 91 def pdf @pdf end |
Instance Method Details
#bottom ⇒ Object
y-coordinate of the bottom
142 143 144 |
# File 'lib/prawn/layout/grid.rb', line 142 def bottom @bottom ||= top - height end |
#bottom_left ⇒ Object
x,y coordinates of bottom left corner
157 158 159 |
# File 'lib/prawn/layout/grid.rb', line 157 def bottom_left [left, bottom] end |
#bottom_right ⇒ Object
x,y coordinates of bottom right corner
162 163 164 |
# File 'lib/prawn/layout/grid.rb', line 162 def bottom_right [right, bottom] end |
#bounding_box(&blk) ⇒ Object
Creates a standard bounding box based on the grid box.
167 168 169 |
# File 'lib/prawn/layout/grid.rb', line 167 def bounding_box(&blk) pdf.bounding_box(top_left, :width => width, :height => height, &blk) end |
#gutter ⇒ Object
Width of the gutter
122 123 124 |
# File 'lib/prawn/layout/grid.rb', line 122 def gutter grid.gutter.to_f end |
#height ⇒ Object
Height of a box
117 118 119 |
# File 'lib/prawn/layout/grid.rb', line 117 def height grid.row_height.to_f end |
#left ⇒ Object
x-coordinate of left side
127 128 129 |
# File 'lib/prawn/layout/grid.rb', line 127 def left @left ||= (width + grid.column_gutter) * @j.to_f end |
#name ⇒ Object
Mostly diagnostic method that outputs the name of a box as col_num, row_num
102 103 104 |
# File 'lib/prawn/layout/grid.rb', line 102 def name "#{@i.to_s},#{@j.to_s}" end |
#right ⇒ Object
x-coordinate of right side
132 133 134 |
# File 'lib/prawn/layout/grid.rb', line 132 def right @right ||= left + width end |
#show(grid_color = "CCCCCC") ⇒ Object
Diagnostic method
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/prawn/layout/grid.rb', line 172 def show(grid_color = "CCCCCC") self.bounding_box do original_stroke_color = pdf.stroke_color pdf.stroke_color = grid_color pdf.text self.name pdf.stroke_bounds pdf.stroke_color = original_stroke_color end end |
#top ⇒ Object
y-coordinate of the top
137 138 139 |
# File 'lib/prawn/layout/grid.rb', line 137 def top @top ||= total_height - ((height + grid.row_gutter) * @i.to_f) end |
#top_left ⇒ Object
x,y coordinates of top left corner
147 148 149 |
# File 'lib/prawn/layout/grid.rb', line 147 def top_left [left, top] end |
#top_right ⇒ Object
x,y coordinates of top right corner
152 153 154 |
# File 'lib/prawn/layout/grid.rb', line 152 def top_right [right, top] end |
#total_height ⇒ Object
:nodoc
107 108 109 |
# File 'lib/prawn/layout/grid.rb', line 107 def total_height pdf.bounds.height.to_f end |
#width ⇒ Object
Width of a box
112 113 114 |
# File 'lib/prawn/layout/grid.rb', line 112 def width grid.column_width.to_f end |