Class: Prawn::Document::BoundingBox
- Inherits:
-
Object
- Object
- Prawn::Document::BoundingBox
- Defined in:
- 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
Stable API collapse
-
#width ⇒ Object
readonly
Width of the bounding box.
Stable API 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.
-
#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
(also: #update_height)
Height of the bounding box.
-
#left ⇒ Object
Relative left x-coordinate of the bounding box.
-
#right ⇒ Object
Relative right x-coordinate of the bounding box.
-
#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.
Extension API collapse
-
#move_past_bottom ⇒ Object
Moves to the top of the next page of the document, starting a new page if necessary.
-
#reference_bounds ⇒ Object
Returns the innermost non-stretchy bounding box.
-
#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.
Instance Attribute Details
#width ⇒ Object (readonly)
Width of the bounding box
452 453 454 |
# File 'lib/prawn/document/bounding_box.rb', line 452 def width @width end |
Instance Method Details
#absolute_bottom ⇒ Object
Absolute bottom y-coordinate of the bottom box
423 424 425 |
# File 'lib/prawn/document/bounding_box.rb', line 423 def absolute_bottom @y - height end |
#absolute_bottom_left ⇒ Object
Absolute bottom-left point of the bounding box
441 442 443 |
# File 'lib/prawn/document/bounding_box.rb', line 441 def absolute_bottom_left [absolute_left, absolute_bottom] end |
#absolute_bottom_right ⇒ Object
Absolute bottom-left point of the bounding box
447 448 449 |
# File 'lib/prawn/document/bounding_box.rb', line 447 def absolute_bottom_right [absolute_right, absolute_bottom] end |
#absolute_left ⇒ Object
Absolute left x-coordinate of the bounding box
405 406 407 |
# File 'lib/prawn/document/bounding_box.rb', line 405 def absolute_left @x end |
#absolute_right ⇒ Object
Absolute right x-coordinate of the bounding box
411 412 413 |
# File 'lib/prawn/document/bounding_box.rb', line 411 def absolute_right @x + width end |
#absolute_top ⇒ Object
Absolute top y-coordinate of the bounding box
417 418 419 |
# File 'lib/prawn/document/bounding_box.rb', line 417 def absolute_top @y end |
#absolute_top_left ⇒ Object
Absolute top-left point of the bounding box
429 430 431 |
# File 'lib/prawn/document/bounding_box.rb', line 429 def absolute_top_left [absolute_left, absolute_top] end |
#absolute_top_right ⇒ Object
Absolute top-right point of the bounding box
435 436 437 |
# File 'lib/prawn/document/bounding_box.rb', line 435 def absolute_top_right [absolute_right, absolute_top] 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:
draw_text('hello', :at => [0, (bounds.bottom + 3)])
349 350 351 |
# File 'lib/prawn/document/bounding_box.rb', line 349 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
399 400 401 |
# File 'lib/prawn/document/bounding_box.rb', line 399 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
387 388 389 |
# File 'lib/prawn/document/bounding_box.rb', line 387 def bottom_right [right, bottom] end |
#height ⇒ Object Also known as: update_height
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.
458 459 460 461 462 463 464 |
# File 'lib/prawn/document/bounding_box.rb', line 458 def height return @height if @height @stretched_height = [ (absolute_top - @document.y), @stretched_height.to_f ].max 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:
draw_text('hello', :at => [(bounds.left + 3), 0])
263 264 265 |
# File 'lib/prawn/document/bounding_box.rb', line 263 def left 0 end |
#move_past_bottom ⇒ Object
Moves to the top of the next page of the document, starting a new page if necessary.
483 484 485 486 487 488 489 |
# File 'lib/prawn/document/bounding_box.rb', line 483 def move_past_bottom if @document.page_number == @document.page_count @document.start_new_page else @document.go_to_page(@document.page_number + 1) end end |
#reference_bounds ⇒ Object
Returns the innermost non-stretchy bounding box.
501 502 503 504 505 506 507 508 |
# File 'lib/prawn/document/bounding_box.rb', line 501 def reference_bounds if stretchy? raise "Can't find reference bounds: my parent is unset" unless @parent @parent.reference_bounds else self end 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:
draw_text('hello', :at => [(bounds.right - 3), 0])
329 330 331 |
# File 'lib/prawn/document/bounding_box.rb', line 329 def right @width 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.
495 496 497 |
# File 'lib/prawn/document/bounding_box.rb', line 495 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:
draw_text('hello', :at => [0, (bounds.top - 3)])
339 340 341 |
# File 'lib/prawn/document/bounding_box.rb', line 339 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.top_left, bounds.bottom_right)
end
362 363 364 |
# File 'lib/prawn/document/bounding_box.rb', line 362 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
375 376 377 |
# File 'lib/prawn/document/bounding_box.rb', line 375 def top_right [right, top] end |