Class: Prawn::Document::BoundingBox

Inherits:
Object
  • Object
show all
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

ColumnBox

Stable API (collapse)

Stable API (collapse)

Extension API (collapse)

Instance Attribute Details

- (Object) width (readonly)

Width of the bounding box



451
452
453
# File 'lib/prawn/document/bounding_box.rb', line 451

def width
  @width
end

Instance Method Details

- (Object) absolute_bottom

Absolute bottom y-coordinate of the bottom box



422
423
424
# File 'lib/prawn/document/bounding_box.rb', line 422

def absolute_bottom
  @y - height
end

- (Object) absolute_bottom_left

Absolute bottom-left point of the bounding box



440
441
442
# File 'lib/prawn/document/bounding_box.rb', line 440

def absolute_bottom_left
  [absolute_left, absolute_bottom]
end

- (Object) absolute_bottom_right

Absolute bottom-left point of the bounding box



446
447
448
# File 'lib/prawn/document/bounding_box.rb', line 446

def absolute_bottom_right
  [absolute_right, absolute_bottom]
end

- (Object) absolute_left

Absolute left x-coordinate of the bounding box



404
405
406
# File 'lib/prawn/document/bounding_box.rb', line 404

def absolute_left
  @x
end

- (Object) absolute_right

Absolute right x-coordinate of the bounding box



410
411
412
# File 'lib/prawn/document/bounding_box.rb', line 410

def absolute_right
  @x + width
end

- (Object) absolute_top

Absolute top y-coordinate of the bounding box



416
417
418
# File 'lib/prawn/document/bounding_box.rb', line 416

def absolute_top
  @y
end

- (Object) absolute_top_left

Absolute top-left point of the bounding box



428
429
430
# File 'lib/prawn/document/bounding_box.rb', line 428

def absolute_top_left
  [absolute_left, absolute_top]
end

- (Object) absolute_top_right

Absolute top-right point of the bounding box



434
435
436
# File 'lib/prawn/document/bounding_box.rb', line 434

def absolute_top_right
  [absolute_right, absolute_top]
end

- (Object) bottom

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)])


348
349
350
# File 'lib/prawn/document/bounding_box.rb', line 348

def bottom
  0
end

- (Object) bottom_left

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


398
399
400
# File 'lib/prawn/document/bounding_box.rb', line 398

def bottom_left
  [left, bottom]
end

- (Object) bottom_right

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


386
387
388
# File 'lib/prawn/document/bounding_box.rb', line 386

def bottom_right
  [right, bottom]
end

- (Object) height 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.



457
458
459
460
461
# File 'lib/prawn/document/bounding_box.rb', line 457

def height
  return @height if @height
  @stretched_height = [(absolute_top - @document.y),
                       @stretched_height.to_f].max
end

- (Object) left

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

- (Object) move_past_bottom

Moves to the top of the next page of the document, starting a new page if necessary.



480
481
482
483
484
485
486
# File 'lib/prawn/document/bounding_box.rb', line 480

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

- (Object) reference_bounds

Returns the innermost non-stretchy bounding box.



497
498
499
500
501
502
503
504
# File 'lib/prawn/document/bounding_box.rb', line 497

def reference_bounds
  if stretchy?
    fail "Can't find reference bounds: my parent is unset" unless @parent
    @parent.reference_bounds
  else
    self
  end
end

- (Object) right

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])


328
329
330
# File 'lib/prawn/document/bounding_box.rb', line 328

def right
  @width
end

- (Boolean) stretchy?

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.

Returns:

  • (Boolean)


491
492
493
# File 'lib/prawn/document/bounding_box.rb', line 491

def stretchy?
  !@height
end

- (Object) top

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)])


338
339
340
# File 'lib/prawn/document/bounding_box.rb', line 338

def top
  height
end

- (Object) top_left

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


361
362
363
# File 'lib/prawn/document/bounding_box.rb', line 361

def top_left
  [left, top]
end

- (Object) top_right

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


374
375
376
# File 'lib/prawn/document/bounding_box.rb', line 374

def top_right
  [right, top]
end