Class: Prawn::Document::GridBox
- Inherits:
-
Object
- Object
- Prawn::Document::GridBox
- Defined in:
- lib/prawn/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
Experimental API collapse
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
Experimental API 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) ⇒ GridBox
constructor
A new instance of GridBox.
-
#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) ⇒ GridBox
Returns a new instance of GridBox.
110 111 112 113 114 |
# File 'lib/prawn/grid.rb', line 110 def initialize(pdf, i, j) @pdf = pdf @i = i @j = j end |
Instance Attribute Details
#pdf ⇒ Object (readonly)
Returns the value of attribute pdf.
108 109 110 |
# File 'lib/prawn/grid.rb', line 108 def pdf @pdf end |
Instance Method Details
#bottom ⇒ Object
y-coordinate of the bottom
159 160 161 |
# File 'lib/prawn/grid.rb', line 159 def bottom @bottom ||= top - height end |
#bottom_left ⇒ Object
x,y coordinates of bottom left corner
174 175 176 |
# File 'lib/prawn/grid.rb', line 174 def bottom_left [left, bottom] end |
#bottom_right ⇒ Object
x,y coordinates of bottom right corner
179 180 181 |
# File 'lib/prawn/grid.rb', line 179 def bottom_right [right, bottom] end |
#bounding_box(&blk) ⇒ Object
Creates a standard bounding box based on the grid box.
184 185 186 |
# File 'lib/prawn/grid.rb', line 184 def bounding_box(&blk) pdf.bounding_box(top_left, :width => width, :height => height, &blk) end |
#gutter ⇒ Object
Width of the gutter
139 140 141 |
# File 'lib/prawn/grid.rb', line 139 def gutter grid.gutter.to_f end |
#height ⇒ Object
Height of a box
134 135 136 |
# File 'lib/prawn/grid.rb', line 134 def height grid.row_height.to_f end |
#left ⇒ Object
x-coordinate of left side
144 145 146 |
# File 'lib/prawn/grid.rb', line 144 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
119 120 121 |
# File 'lib/prawn/grid.rb', line 119 def name "#{@i.to_s},#{@j.to_s}" end |
#right ⇒ Object
x-coordinate of right side
149 150 151 |
# File 'lib/prawn/grid.rb', line 149 def right @right ||= left + width end |
#show(grid_color = "CCCCCC") ⇒ Object
Diagnostic method
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/prawn/grid.rb', line 189 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
154 155 156 |
# File 'lib/prawn/grid.rb', line 154 def top @top ||= total_height - ((height + grid.row_gutter) * @i.to_f) end |
#top_left ⇒ Object
x,y coordinates of top left corner
164 165 166 |
# File 'lib/prawn/grid.rb', line 164 def top_left [left, top] end |
#top_right ⇒ Object
x,y coordinates of top right corner
169 170 171 |
# File 'lib/prawn/grid.rb', line 169 def top_right [right, top] end |
#total_height ⇒ Object
:nodoc
124 125 126 |
# File 'lib/prawn/grid.rb', line 124 def total_height pdf.bounds.height.to_f end |
#width ⇒ Object
Width of a box
129 130 131 |
# File 'lib/prawn/grid.rb', line 129 def width grid.column_width.to_f end |