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 #bounding_box for a description of what this class is used for.

Direct Known Subclasses

ColumnBox

Defined Under Namespace

Classes: NoReferenceBounds

Stable API collapse

Stable API collapse

Extension API collapse

Instance Attribute Details

#widthNumber (readonly)

Width of the bounding box.

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 522
522
def width
523
  @width
524
end

Instance Method Details

#absolute_bottomNumber

Absolute bottom y-coordinate of the bottom box.

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 487
487
def absolute_bottom
488
  @y - height
489
end

#absolute_bottom_leftArray(Number, Number)

Absolute bottom-left point of the bounding box.

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 508
508
def absolute_bottom_left
509
  [absolute_left, absolute_bottom]
510
end

#absolute_bottom_rightArray(Number, Number)

Absolute bottom-left point of the bounding box.

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 515
515
def absolute_bottom_right
516
  [absolute_right, absolute_bottom]
517
end

#absolute_leftNumber

Absolute left x-coordinate of the bounding box.

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 466
466
def absolute_left
467
  @x
468
end

#absolute_rightNumber

Absolute right x-coordinate of the bounding box.

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 473
473
def absolute_right
474
  @x + width
475
end

#absolute_topNumber

Absolute top y-coordinate of the bounding box.

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 480
480
def absolute_top
481
  @y
482
end

#absolute_top_leftArray(Number, Number)

Absolute top-left point of the bounding box.

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 494
494
def absolute_top_left
495
  [absolute_left, absolute_top]
496
end

#absolute_top_rightArray(Number, Number)

Absolute top-right point of the bounding box.

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 501
501
def absolute_top_right
502
  [absolute_right, absolute_top]
503
end

#bottomNumber

Relative bottom y-coordinate of the bounding box. Always 0.

Examples:

Position some text 3 pts from the bottom of the containing box

draw_text('hello', at: [0, (bounds.bottom + 3)])

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 411
411
def bottom
412
  0
413
end

#bottom_leftArray(Number, Number)

Relative bottom-left point of the bounding box.

Examples:

Draw a line along the left hand side of the page

stroke do
  line(bounds.bottom_left, bounds.top_left)
end

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 459
459
def bottom_left
460
  [left, bottom]
461
end

#bottom_rightArray(Number, Number)

Relative bottom-right point of the bounding box.

Examples:

Draw a line along the right hand side of the page

stroke do
  line(bounds.bottom_right, bounds.top_right)
end

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 447
447
def bottom_right
448
  [right, bottom]
449
end

#heightNumber 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.

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 529
529
def height
530
  return @height if @height
531
532
  @stretched_height = [
533
    (absolute_top - @document.y),
534
    Float(@stretched_height || 0.0),
535
  ].max
536
end

#leftNumber

Relative left x-coordinate of the bounding box. Always 0.

Examples:

Position some text 3 pts from the left of the containing box

draw_text('hello', at: [(bounds.left + 3), 0])

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 312
312
def left
313
  0
314
end

#move_past_bottomvoid

This method returns an undefined value.

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

Source Code
lib/prawn/document/bounding_box.rb, line 560
560
def move_past_bottom
561
  if @document.page_number == @document.page_count
562
    @document.start_new_page
563
  else
564
    @document.go_to_page(@document.page_number + 1)
565
  end
566
end

#reference_boundsBoundingBox

Returns the innermost non-stretchy bounding box.

Returns:

Raises:

Source Code
lib/prawn/document/bounding_box.rb, line 581
581
def reference_bounds
582
  if stretchy?
583
    raise NoReferenceBounds unless @parent
584
585
    @parent.reference_bounds
586
  else
587
    self
588
  end
589
end

#rightNumber

Relative right x-coordinate of the bounding box. Equal to the box width.

Examples:

Position some text 3 pts from the right of the containing box

draw_text('hello', at: [(bounds.right - 3), 0])

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 391
391
def right
392
  @width
393
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.

Returns:

  • (Boolean)
Source Code
lib/prawn/document/bounding_box.rb, line 573
573
def stretchy?
574
  !@height
575
end

#topNumber

Relative top y-coordinate of the bounding box. Equal to the box height.

Examples:

Position some text 3 pts from the top of the containing box

draw_text('hello', at: [0, (bounds.top - 3)])

Returns:

  • (Number)
Source Code
lib/prawn/document/bounding_box.rb, line 401
401
def top
402
  height
403
end

#top_leftArray(Number, Number)

Relative top-left point of the bounding_box.

Examples:

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

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 423
423
def top_left
424
  [left, top]
425
end

#top_rightArray(Number, Number)

Relative top-right point of the bounding box.

Examples:

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

Returns:

  • (Array(Number, Number))
Source Code
lib/prawn/document/bounding_box.rb, line 435
435
def top_right
436
  [right, top]
437
end