Class: Prawn::Document::BoundingBox
- Inherits:
-
Object
- Object
- Prawn::Document::BoundingBox
- Defined in:
- lib/prawn/document/column_box.rb,
lib/prawn/document/bounding_box.rb
Overview
Low level layout helper that simplifies coordinate math.
See Prawn::Document#bounding_box for a description of what this class is used for.
Direct Known Subclasses
Instance Method Summary collapse
-
#absolute_bottom ⇒ Object
Absolute bottom y-coordinate of the bottom box.
-
#absolute_bottom_left ⇒ Object
Absolute bottom-left point of the bounding box.
-
#absolute_bottom_right ⇒ Object
Absolute bottom-left point of the bounding box.
-
#absolute_left ⇒ Object
Absolute left x-coordinate of the bounding box.
-
#absolute_right ⇒ Object
Absolute right x-coordinate of the bounding box.
-
#absolute_top ⇒ Object
Absolute top y-coordinate of the bounding box.
-
#absolute_top_left ⇒ Object
Absolute top-left point of the bounding box.
-
#absolute_top_right ⇒ Object
Absolute top-right point of the bounding box.
-
#anchor ⇒ Object
The translated origin (x,y-height) which describes the location of the bottom left corner of the bounding box.
-
#bottom ⇒ Object
Relative bottom y-coordinate of the bounding box (Always 0).
-
#bottom_left ⇒ Object
Relative bottom-left point of the bounding box.
-
#bottom_right ⇒ Object
Relative bottom-right point of the bounding box.
-
#height ⇒ Object
Height of the bounding box.
-
#indent(left_padding, &block) ⇒ Object
Temporarily adjust the @x coordinate to allow for left_padding.
-
#initialize(parent, point, options = {}) ⇒ BoundingBox
constructor
:nodoc:.
-
#left ⇒ Object
Relative left x-coordinate of the bounding box.
- #left_side ⇒ Object
- #move_past_bottom ⇒ Object
-
#right ⇒ Object
Relative right x-coordinate of the bounding box.
- #right_side ⇒ Object
-
#stretchy? ⇒ Boolean
Returns
false
when the box has a defined height,true
when the height is being calculated on the fly based on the current vertical position. -
#top ⇒ Object
Relative top y-coordinate of the bounding box.
-
#top_left ⇒ Object
Relative top-left point of the bounding_box.
-
#top_right ⇒ Object
Relative top-right point of the bounding box.
-
#width ⇒ Object
Width of the bounding box.
Constructor Details
#initialize(parent, point, options = {}) ⇒ BoundingBox
:nodoc:
198 199 200 201 202 |
# File 'lib/prawn/document/bounding_box.rb', line 198 def initialize(parent, point, ={}) #:nodoc: @parent = parent @x, @y = point @width, @height = [:width], [:height] end |
Instance Method Details
#absolute_bottom ⇒ Object
Absolute bottom y-coordinate of the bottom box
333 334 335 |
# File 'lib/prawn/document/bounding_box.rb', line 333 def absolute_bottom @y - height end |
#absolute_bottom_left ⇒ Object
Absolute bottom-left point of the bounding box
351 352 353 |
# File 'lib/prawn/document/bounding_box.rb', line 351 def absolute_bottom_left [absolute_left, absolute_bottom] end |
#absolute_bottom_right ⇒ Object
Absolute bottom-left point of the bounding box
357 358 359 |
# File 'lib/prawn/document/bounding_box.rb', line 357 def absolute_bottom_right [absolute_right, absolute_bottom] end |
#absolute_left ⇒ Object
Absolute left x-coordinate of the bounding box
315 316 317 |
# File 'lib/prawn/document/bounding_box.rb', line 315 def absolute_left @x end |
#absolute_right ⇒ Object
Absolute right x-coordinate of the bounding box
321 322 323 |
# File 'lib/prawn/document/bounding_box.rb', line 321 def absolute_right @x + width end |
#absolute_top ⇒ Object
Absolute top y-coordinate of the bounding box
327 328 329 |
# File 'lib/prawn/document/bounding_box.rb', line 327 def absolute_top @y end |
#absolute_top_left ⇒ Object
Absolute top-left point of the bounding box
339 340 341 |
# File 'lib/prawn/document/bounding_box.rb', line 339 def absolute_top_left [absolute_left, absolute_top] end |
#absolute_top_right ⇒ Object
Absolute top-right point of the bounding box
345 346 347 |
# File 'lib/prawn/document/bounding_box.rb', line 345 def absolute_top_right [absolute_right, absolute_top] end |
#anchor ⇒ Object
The translated origin (x,y-height) which describes the location of the bottom left corner of the bounding box
207 208 209 |
# File 'lib/prawn/document/bounding_box.rb', line 207 def anchor [@x, @y - height] end |
#bottom ⇒ Object
Relative bottom y-coordinate of the bounding box (Always 0)
Example, position some text 3 pts from the bottom of the containing box:
text('hello', :at => [0, (bounds.bottom + 3)])
259 260 261 |
# File 'lib/prawn/document/bounding_box.rb', line 259 def bottom 0 end |
#bottom_left ⇒ Object
Relative bottom-left point of the bounding box
Example, draw a line along the left hand side of the page:
stroke do
line(bounds.bottom_left, bounds.top_left)
end
309 310 311 |
# File 'lib/prawn/document/bounding_box.rb', line 309 def bottom_left [left,bottom] end |
#bottom_right ⇒ Object
Relative bottom-right point of the bounding box
Example, draw a line along the right hand side of the page:
stroke do
line(bounds.bottom_right, bounds.top_right)
end
297 298 299 |
# File 'lib/prawn/document/bounding_box.rb', line 297 def bottom_right [right,bottom] end |
#height ⇒ Object
Height of the bounding box. If the box is ‘stretchy’ (unspecified height attribute), height is calculated as the distance from the top of the box to the current drawing position.
371 372 373 |
# File 'lib/prawn/document/bounding_box.rb', line 371 def height @height || absolute_top - @parent.y end |
#indent(left_padding, &block) ⇒ Object
Temporarily adjust the @x coordinate to allow for left_padding
224 225 226 227 228 229 230 231 |
# File 'lib/prawn/document/bounding_box.rb', line 224 def indent(left_padding, &block) @x += left_padding @width -= left_padding yield ensure @x -= left_padding @width += left_padding end |
#left ⇒ Object
Relative left x-coordinate of the bounding box. (Always 0)
Example, position some text 3 pts from the left of the containing box:
text('hello', :at => [(bounds.left + 3), 0])
217 218 219 |
# File 'lib/prawn/document/bounding_box.rb', line 217 def left 0 end |
#left_side ⇒ Object
46 47 48 |
# File 'lib/prawn/document/column_box.rb', line 46 def left_side absolute_left end |
#move_past_bottom ⇒ Object
54 55 56 |
# File 'lib/prawn/document/column_box.rb', line 54 def move_past_bottom @parent.start_new_page end |
#right ⇒ Object
Relative right x-coordinate of the bounding box. (Equal to the box width)
Example, position some text 3 pts from the right of the containing box:
text('hello', :at => [(bounds.right - 3), 0])
239 240 241 |
# File 'lib/prawn/document/bounding_box.rb', line 239 def right @width end |
#right_side ⇒ Object
50 51 52 |
# File 'lib/prawn/document/column_box.rb', line 50 def right_side absolute_right end |
#stretchy? ⇒ Boolean
Returns false
when the box has a defined height, true
when the height is being calculated on the fly based on the current vertical position.
378 379 380 |
# File 'lib/prawn/document/bounding_box.rb', line 378 def stretchy? !@height end |
#top ⇒ Object
Relative top y-coordinate of the bounding box. (Equal to the box height)
Example, position some text 3 pts from the top of the containing box:
text('hello', :at => [0, (bounds.top - 3)])
249 250 251 |
# File 'lib/prawn/document/bounding_box.rb', line 249 def top height end |
#top_left ⇒ Object
Relative top-left point of the bounding_box
Example, draw a line from the top left of the box diagonally to the bottom right:
stroke do
line(bounds., bounds.bottom_right)
end
272 273 274 |
# File 'lib/prawn/document/bounding_box.rb', line 272 def top_left [left,top] end |
#top_right ⇒ Object
Relative top-right point of the bounding box
Example, draw a line from the top_right of the box diagonally to the bottom left:
stroke do
line(bounds.top_right, bounds.bottom_left)
end
285 286 287 |
# File 'lib/prawn/document/bounding_box.rb', line 285 def top_right [right,top] end |
#width ⇒ Object
Width of the bounding box
363 364 365 |
# File 'lib/prawn/document/bounding_box.rb', line 363 def width @width end |