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 116
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 165
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 180
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 185
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 190
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 145
def gutter
  grid.gutter.to_f
end
height() click to toggle source

Height of a box

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

x-coordinate of left side

# File lib/prawn/grid.rb, line 150
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 125
def name
  "#{@rows},#{@columns}"
end
right() click to toggle source

x-coordinate of right side

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

Diagnostic method

# File lib/prawn/grid.rb, line 195
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 160
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 170
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 175
def top_right
  [right, top]
end
total_height() click to toggle source

:nodoc

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

Width of a box

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

Private Instance Methods

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