class Prawn::Document::GridBox

A Box is a class that represents a bounded area of a page. A Grid object has methods that allow easy access to the coordinates of its corners, which can be plugged into most existing prawnmethods.

@group Experimental API

Attributes

pdf[R]

Public Class Methods

new(pdf, rows, columns) click to toggle source
# File lib/prawn/grid.rb, line 115
def initialize(pdf, rows, columns)
  @pdf = pdf
  @rows = rows
  @columns = columns
end

Public Instance Methods

bottom() click to toggle source

y-coordinate of the bottom

# File lib/prawn/grid.rb, line 164
def bottom
  @bottom ||= top - height
end
bottom_left() click to toggle source

x,y coordinates of bottom left corner

# File lib/prawn/grid.rb, line 179
def bottom_left
  [left, bottom]
end
bottom_right() click to toggle source

x,y coordinates of bottom right corner

# File lib/prawn/grid.rb, line 184
def bottom_right
  [right, bottom]
end
bounding_box(&blk) click to toggle source

Creates a standard bounding box based on the grid box.

# File lib/prawn/grid.rb, line 189
def bounding_box(&blk)
  pdf.bounding_box(top_left, width: width, height: height, &blk)
end
gutter() click to toggle source

Width of the gutter

# File lib/prawn/grid.rb, line 144
def gutter
  grid.gutter.to_f
end
height() click to toggle source

Height of a box

# File lib/prawn/grid.rb, line 139
def height
  grid.row_height.to_f
end
left() click to toggle source

x-coordinate of left side

# File lib/prawn/grid.rb, line 149
def left
  @left ||= (width + grid.column_gutter) * @columns.to_f
end
name() click to toggle source

Mostly diagnostic method that outputs the name of a box as col_num, row_num

# File lib/prawn/grid.rb, line 124
def name
  "#{@rows},#{@columns}"
end
right() click to toggle source

x-coordinate of right side

# File lib/prawn/grid.rb, line 154
def right
  @right ||= left + width
end
show(grid_color = 'CCCCCC') click to toggle source

Diagnostic method

# File lib/prawn/grid.rb, line 194
def show(grid_color = 'CCCCCC')
  bounding_box do
    original_stroke_color = pdf.stroke_color

    pdf.stroke_color = grid_color
    pdf.text name
    pdf.stroke_bounds

    pdf.stroke_color = original_stroke_color
  end
end
top() click to toggle source

y-coordinate of the top

# File lib/prawn/grid.rb, line 159
def top
  @top ||= total_height - ((height + grid.row_gutter) * @rows.to_f)
end
top_left() click to toggle source

x,y coordinates of top left corner

# File lib/prawn/grid.rb, line 169
def top_left
  [left, top]
end
top_right() click to toggle source

x,y coordinates of top right corner

# File lib/prawn/grid.rb, line 174
def top_right
  [right, top]
end
total_height() click to toggle source

:nodoc

# File lib/prawn/grid.rb, line 129
def total_height
  pdf.bounds.height.to_f
end
width() click to toggle source

Width of a box

# File lib/prawn/grid.rb, line 134
def width
  grid.column_width.to_f
end

Private Instance Methods

grid() click to toggle source
# File lib/prawn/grid.rb, line 208
def grid
  pdf.grid
end