### Home Classes Methods

### In Files

- lib/prawn/document/bounding_box.rb

### Parent

Object

### Methods

- ::new
- ::restore_deep_copy
- #absolute_bottom
- #absolute_bottom_left
- #absolute_bottom_right
- #absolute_left
- #absolute_right
- #absolute_top
- #absolute_top_left
- #absolute_top_right
- #add_left_padding
- #add_right_padding
- #anchor
- #bottom
- #bottom_left
- #bottom_right
- #deep_copy
- #height
- #indent
- #left
- #left_side
- #move_past_bottom
- #reference_bounds
- #right
- #right_side
- #stretchy?
- #subtract_left_padding
- #subtract_right_padding
- #top
- #top_left
- #top_right
- #update_height
- #width

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Prawn::Document::BoundingBox

Low level layout helper that simplifies coordinate math.

See Prawn::Document#bounding_box for a description of what this class is used for.

### Attributes

document[R]

@private

parent[R]

@private

total_left_padding[R]

@private The current indentation of the left side of the bounding box.

total_right_padding[R]

@private The current indentation of the right side of the bounding box.

### Public Class Methods

new(document, parent, point, options={}) click to toggle source

    # File lib/prawn/document/bounding_box.rb, line 222
    def initialize(document, parent, point, options={}) # @private
      unless options[:width]
        raise ArgumentError, "BoundingBox needs the :width option to be set"
      end

      @document = document
      @parent = parent
      @x, @y = point
      @width, @height = options[:width], options[:height]
      @total_left_padding = 0
      @total_right_padding = 0
      @stretched_height = nil
    end

restore_deep_copy(bounds, document) click to toggle source

Restores a copy of the bounds taken by BoundingBox.deep_copy in the context of the given `document`. Does not set the bounds of the document to the resulting BoundingBox, only returns it.

@private

    # File lib/prawn/document/bounding_box.rb, line 530
    def self.restore_deep_copy(bounds, document)
      bounds.instance_variable_set("@document", document)
      bounds
    end

### Public Instance Methods

absolute_bottom() click to toggle source

Absolute bottom y-coordinate of the bottom box

    # File lib/prawn/document/bounding_box.rb, line 422
    def absolute_bottom
      @y - height
    end

absolute_bottom_left() click to toggle source

Absolute bottom-left point of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 440
    def absolute_bottom_left
      [absolute_left, absolute_bottom]
    end

absolute_bottom_right() click to toggle source

Absolute bottom-left point of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 446
    def absolute_bottom_right
      [absolute_right, absolute_bottom]
    end

absolute_left() click to toggle source

Absolute left x-coordinate of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 404
    def absolute_left
      @x
    end

absolute_right() click to toggle source

Absolute right x-coordinate of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 410
    def absolute_right
      @x + width
    end

absolute_top() click to toggle source

Absolute top y-coordinate of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 416
    def absolute_top
      @y
    end

absolute_top_left() click to toggle source

Absolute top-left point of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 428
    def absolute_top_left
      [absolute_left, absolute_top]
    end

absolute_top_right() click to toggle source

Absolute top-right point of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 434
    def absolute_top_right
      [absolute_right, absolute_top]
    end

add_left_padding(left_padding) click to toggle source

Increase the left padding of the bounding box. @private

    # File lib/prawn/document/bounding_box.rb, line 294
    def add_left_padding(left_padding)
      @total_left_padding += left_padding
      @x += left_padding
      @width -= left_padding
    end

add_right_padding(right_padding) click to toggle source

Increase the right padding of the bounding box. @private

    # File lib/prawn/document/bounding_box.rb, line 310
    def add_right_padding(right_padding)
      @total_right_padding += right_padding
      @width -= right_padding
    end

anchor() click to toggle source

The translated origin (x,y-height) which describes the location of the bottom left corner of the bounding box

@private

    # File lib/prawn/document/bounding_box.rb, line 252
    def anchor
      [@x, @y - height]
    end

bottom() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 348
    def bottom
      0
    end

bottom_left() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 398
    def bottom_left
      [left,bottom]
    end

bottom_right() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 386
    def bottom_right
      [right,bottom]
    end

deep_copy() click to toggle source

Returns a deep copy of these bounds (including all parent bounds but not copying the reference to the Document).

@private

    # File lib/prawn/document/bounding_box.rb, line 515
    def deep_copy
      copy = dup
      # Deep-copy the parent bounds
      copy.instance_variable_set("@parent", if BoundingBox === @parent
                                              @parent.deep_copy
                                            end)
      copy.instance_variable_set("@document", nil)
      copy
    end

height() click to toggle source

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.

    # File lib/prawn/document/bounding_box.rb, line 460
    def height
      return @height if @height
      @stretched_height = [(absolute_top - @document.y),
                           @stretched_height.to_f].max
    end

Also aliased as: update_height
indent(left_padding, right_padding = 0, &block) click to toggle source

Temporarily adjust the @x coordinate to allow for left_padding

Example:

    indent 20 do
       text "20 points in"
       indent 30 do
         text "50 points in"
       end
     end

    indent 20, 20 do
      text "indented on both sides"
    end

@private

    # File lib/prawn/document/bounding_box.rb, line 283
    def indent(left_padding, right_padding = 0, &block)
      add_left_padding(left_padding)
      add_right_padding(right_padding)
      yield
    ensure
      @document.bounds.subtract_left_padding(left_padding)
      @document.bounds.subtract_right_padding(right_padding)
    end

left() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 262
    def left
      0
    end

left_side() click to toggle source

an alias for absolute_left @private

    # File lib/prawn/document/bounding_box.rb, line 468
    def left_side
      absolute_left
    end

move_past_bottom() click to toggle source

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

    # 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() click to toggle source

Returns the innermost non-stretchy bounding box.

    # File lib/prawn/document/bounding_box.rb, line 500
    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() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 328
    def right
      @width
    end

right_side() click to toggle source

an alias for absolute_right @private

    # File lib/prawn/document/bounding_box.rb, line 474
    def right_side
      absolute_right
    end

stretchy?() click to toggle source

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.

    # File lib/prawn/document/bounding_box.rb, line 494
    def stretchy?
      !@height
    end

subtract_left_padding(left_padding) click to toggle source

Decrease the left padding of the bounding box. @private

    # File lib/prawn/document/bounding_box.rb, line 302
    def subtract_left_padding(left_padding)
      @total_left_padding -= left_padding
      @x -= left_padding
      @width += left_padding
    end

subtract_right_padding(right_padding) click to toggle source

Decrease the right padding of the bounding box. @private

    # File lib/prawn/document/bounding_box.rb, line 317
    def subtract_right_padding(right_padding)
      @total_right_padding -= right_padding
      @width += right_padding
    end

top() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 338
    def top
      height
    end

top_left() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 361
    def top_left
      [left,top]
    end

top_right() click to toggle source

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

    # File lib/prawn/document/bounding_box.rb, line 374
    def top_right
      [right,top]
    end

update_height() click to toggle source
Alias for: height
width() click to toggle source

Width of the bounding box

    # File lib/prawn/document/bounding_box.rb, line 452
    def width
      @width
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.