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 Prawn methods.
Experimental API collapse
-
#bottom ⇒ Float
y-coordinate of the bottom.
-
#bottom_left ⇒ Array(Float, Float)
x,y coordinates of bottom left corner.
-
#bottom_right ⇒ Array(Float, Float)
x,y coordinates of bottom right corner.
-
#bounding_box { ... } ⇒ void
Creates a standard bounding box based on the grid box.
-
#gutter ⇒ Float
Width of the gutter.
-
#height ⇒ Float
Height of a box.
-
#initialize(pdf, rows, columns) ⇒ GridBox
constructor
A new instance of GridBox.
-
#left ⇒ Float
x-coordinate of left side.
-
#name ⇒ String
Mostly diagnostic method that outputs the name of a box as col_num, row_num.
-
#right ⇒ Float
x-coordinate of right side.
-
#show(grid_color = 'CCCCCC') ⇒ void
Drawn the box.
-
#top ⇒ Float
y-coordinate of the top.
-
#top_left ⇒ Array(Float, Float)
x,y coordinates of top left corner.
-
#top_right ⇒ Array(Float, Float)
x,y coordinates of top right corner.
-
#width ⇒ Float
Width of a box.
Constructor Details
#initialize(pdf, rows, columns) ⇒ GridBox
Returns a new instance of GridBox.
Source Code
168 | def initialize(pdf, rows, columns) |
169 | @pdf = pdf |
170 | @rows = rows |
171 | @columns = columns |
172 | end
|
Instance Method Details
#bottom ⇒ Float
y-coordinate of the bottom.
Source Code
232 | def bottom |
233 | @bottom ||= top - height |
234 | end
|
#bottom_left ⇒ Array(Float, Float)
x,y coordinates of bottom left corner.
Source Code
253 | def bottom_left |
254 | [left, bottom] |
255 | end
|
#bottom_right ⇒ Array(Float, Float)
x,y coordinates of bottom right corner.
Source Code
260 | def bottom_right |
261 | [right, bottom] |
262 | end
|
#bounding_box { ... } ⇒ void
This method returns an undefined value.
Creates a standard bounding box based on the grid box.
Source Code
268 | def bounding_box(&blk) |
269 | pdf.bounding_box(top_left, width: width, height: height, &blk) |
270 | end
|
#gutter ⇒ Float
Width of the gutter.
Source Code
204 | def gutter |
205 | Float(grid.gutter) |
206 | end
|
#height ⇒ Float
Height of a box.
Source Code
197 | def height |
198 | Float(grid.row_height) |
199 | end
|
#left ⇒ Float
x-coordinate of left side.
Source Code
211 | def left |
212 | @left ||= (width + grid.column_gutter) * Float(@columns) |
213 | end
|
#name ⇒ String
Mostly diagnostic method that outputs the name of a box as col_num, row_num
Source Code
178 | def name |
179 | "#{@rows},#{@columns}" |
180 | end
|
#right ⇒ Float
x-coordinate of right side.
Source Code
218 | def right |
219 | @right ||= left + width |
220 | end
|
#show(grid_color = 'CCCCCC') ⇒ void
This method returns an undefined value.
Drawn the box. Diagnostic method.
Source Code
276 | def show(grid_color = 'CCCCCC') |
277 | bounding_box do |
278 | original_stroke_color = pdf.stroke_color |
279 | |
280 | pdf.stroke_color = grid_color |
281 | pdf.text(name) |
282 | pdf.stroke_bounds |
283 | |
284 | pdf.stroke_color = original_stroke_color |
285 | end
|
286 | end
|
#top ⇒ Float
y-coordinate of the top.
Source Code
225 | def top |
226 | @top ||= total_height - ((height + grid.row_gutter) * Float(@rows)) |
227 | end
|
#top_left ⇒ Array(Float, Float)
x,y coordinates of top left corner.
Source Code
239 | def top_left |
240 | [left, top] |
241 | end
|
#top_right ⇒ Array(Float, Float)
x,y coordinates of top right corner.
Source Code
246 | def top_right |
247 | [right, top] |
248 | end
|
#width ⇒ Float
Width of a box.
Source Code
190 | def width |
191 | Float(grid.column_width) |
192 | end
|