Class: Prawn::Document::GridBox

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/grid.rb

Overview

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 Prawn methods.

Experimental API collapse

Constructor Details

#initialize(pdf, rows, columns) ⇒ GridBox

Returns a new instance of GridBox.

Source Code
lib/prawn/grid.rb, line 168
168
def initialize(pdf, rows, columns)
169
  @pdf = pdf
170
  @rows = rows
171
  @columns = columns
172
end

Instance Method Details

#bottomFloat

y-coordinate of the bottom.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 232
232
def bottom
233
  @bottom ||= top - height
234
end

#bottom_leftArray(Float, Float)

x,y coordinates of bottom left corner.

Returns:

  • (Array(Float, Float))
Source Code
lib/prawn/grid.rb, line 253
253
def bottom_left
254
  [left, bottom]
255
end

#bottom_rightArray(Float, Float)

x,y coordinates of bottom right corner.

Returns:

  • (Array(Float, Float))
Source Code
lib/prawn/grid.rb, line 260
260
def bottom_right
261
  [right, bottom]
262
end

#bounding_box { ... } ⇒ void

This method returns an undefined value.

Creates a standard bounding box based on the grid box.

Yields:

Source Code
lib/prawn/grid.rb, line 268
268
def bounding_box(&blk)
269
  pdf.bounding_box(top_left, width: width, height: height, &blk)
270
end

#gutterFloat

Width of the gutter.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 204
204
def gutter
205
  Float(grid.gutter)
206
end

#heightFloat

Height of a box.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 197
197
def height
198
  Float(grid.row_height)
199
end

#leftFloat

x-coordinate of left side.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 211
211
def left
212
  @left ||= (width + grid.column_gutter) * Float(@columns)
213
end

#nameString

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

Returns:

  • (String)
Source Code
lib/prawn/grid.rb, line 178
178
def name
179
  "#{@rows},#{@columns}"
180
end

#rightFloat

x-coordinate of right side.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 218
218
def right
219
  @right ||= left + width
220
end

#show(grid_color = 'CCCCCC') ⇒ void

This method returns an undefined value.

Drawn the box. Diagnostic method.

Parameters:

  • grid_color (Color) (defaults to: 'CCCCCC')
Source Code
lib/prawn/grid.rb, line 276
276
def show(grid_color = 'CCCCCC')
277
  bounding_box do
278
    original_stroke_color = pdf.stroke_color
279
280
    pdf.stroke_color = grid_color
281
    pdf.text(name)
282
    pdf.stroke_bounds
283
284
    pdf.stroke_color = original_stroke_color
285
  end
286
end

#topFloat

y-coordinate of the top.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 225
225
def top
226
  @top ||= total_height - ((height + grid.row_gutter) * Float(@rows))
227
end

#top_leftArray(Float, Float)

x,y coordinates of top left corner.

Returns:

  • (Array(Float, Float))
Source Code
lib/prawn/grid.rb, line 239
239
def top_left
240
  [left, top]
241
end

#top_rightArray(Float, Float)

x,y coordinates of top right corner.

Returns:

  • (Array(Float, Float))
Source Code
lib/prawn/grid.rb, line 246
246
def top_right
247
  [right, top]
248
end

#widthFloat

Width of a box.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 190
190
def width
191
  Float(grid.column_width)
192
end