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
:nodoc:.
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.
92 93 94 95 96 |
# File 'lib/prawn/layout/grid.rb', line 92 def initialize(pdf, i, j) @pdf = pdf @i = i @j = j end |
Instance Attribute Details
#pdf ⇒ Object (readonly)
:nodoc:
90 91 92 |
# File 'lib/prawn/layout/grid.rb', line 90 def pdf @pdf end |
Instance Method Details
#bottom ⇒ Object
y-coordinate of the bottom
141 142 143 |
# File 'lib/prawn/layout/grid.rb', line 141 def bottom @bottom ||= top - height end |
#bottom_left ⇒ Object
x,y coordinates of bottom left corner
156 157 158 |
# File 'lib/prawn/layout/grid.rb', line 156 def bottom_left [left, bottom] end |
#bottom_right ⇒ Object
x,y coordinates of bottom right corner
161 162 163 |
# File 'lib/prawn/layout/grid.rb', line 161 def bottom_right [right, bottom] end |
#bounding_box(&blk) ⇒ Object
Creates a standard bounding box based on the grid box.
166 167 168 |
# File 'lib/prawn/layout/grid.rb', line 166 def bounding_box(&blk) pdf.bounding_box(top_left, :width => width, :height => height, &blk) end |
#gutter ⇒ Object
Width of the gutter
121 122 123 |
# File 'lib/prawn/layout/grid.rb', line 121 def gutter grid.gutter.to_f end |
#height ⇒ Object
Height of a box
116 117 118 |
# File 'lib/prawn/layout/grid.rb', line 116 def height grid.row_height.to_f end |
#left ⇒ Object
x-coordinate of left side
126 127 128 |
# File 'lib/prawn/layout/grid.rb', line 126 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
101 102 103 |
# File 'lib/prawn/layout/grid.rb', line 101 def name "#{@i.to_s},#{@j.to_s}" end |
#right ⇒ Object
x-coordinate of right side
131 132 133 |
# File 'lib/prawn/layout/grid.rb', line 131 def right @right ||= left + width end |
#show(grid_color = "CCCCCC") ⇒ Object
Diagnostic method
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/prawn/layout/grid.rb', line 171 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
136 137 138 |
# File 'lib/prawn/layout/grid.rb', line 136 def top @top ||= total_height - ((height + grid.row_gutter) * @i.to_f) end |
#top_left ⇒ Object
x,y coordinates of top left corner
146 147 148 |
# File 'lib/prawn/layout/grid.rb', line 146 def top_left [left, top] end |
#top_right ⇒ Object
x,y coordinates of top right corner
151 152 153 |
# File 'lib/prawn/layout/grid.rb', line 151 def top_right [right, top] end |
#total_height ⇒ Object
:nodoc
106 107 108 |
# File 'lib/prawn/layout/grid.rb', line 106 def total_height pdf.bounds.height.to_f end |
#width ⇒ Object
Width of a box
111 112 113 |
# File 'lib/prawn/layout/grid.rb', line 111 def width grid.column_width.to_f end |