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 prawnmethods.

Direct Known Subclasses

MultiBox

Experimental API (collapse)

Experimental API (collapse)

Constructor Details

- (GridBox) initialize(pdf, i, j)

Returns a new instance of GridBox



114
115
116
117
118
# File 'lib/prawn/grid.rb', line 114

def initialize(pdf, i, j)
  @pdf = pdf
  @i = i
  @j = j
end

Instance Attribute Details

- (Object) pdf (readonly)

Returns the value of attribute pdf



112
113
114
# File 'lib/prawn/grid.rb', line 112

def pdf
  @pdf
end

Instance Method Details

- (Object) bottom

y-coordinate of the bottom



163
164
165
# File 'lib/prawn/grid.rb', line 163

def bottom
  @bottom ||= top - height
end

- (Object) bottom_left

x,y coordinates of bottom left corner



178
179
180
# File 'lib/prawn/grid.rb', line 178

def bottom_left
  [left, bottom]
end

- (Object) bottom_right

x,y coordinates of bottom right corner



183
184
185
# File 'lib/prawn/grid.rb', line 183

def bottom_right
  [right, bottom]
end

- (Object) bounding_box(&blk)

Creates a standard bounding box based on the grid box.



188
189
190
# File 'lib/prawn/grid.rb', line 188

def bounding_box(&blk)
  pdf.bounding_box(top_left, :width => width, :height => height, &blk)
end

- (Object) gutter

Width of the gutter



143
144
145
# File 'lib/prawn/grid.rb', line 143

def gutter
  grid.gutter.to_f
end

- (Object) height

Height of a box



138
139
140
# File 'lib/prawn/grid.rb', line 138

def height
  grid.row_height.to_f
end

- (Object) left

x-coordinate of left side



148
149
150
# File 'lib/prawn/grid.rb', line 148

def left
  @left ||= (width + grid.column_gutter) * @j.to_f
end

- (Object) name

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



123
124
125
# File 'lib/prawn/grid.rb', line 123

def name
  "#{@i.to_s},#{@j.to_s}"
end

- (Object) right

x-coordinate of right side



153
154
155
# File 'lib/prawn/grid.rb', line 153

def right
  @right ||= left + width
end

- (Object) show(grid_color = "CCCCCC")

Diagnostic method



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/prawn/grid.rb', line 193

def show(grid_color = "CCCCCC")
  self.bounding_box do
    original_stroke_color = pdf.stroke_color

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

    pdf.stroke_color = original_stroke_color
  end
end

- (Object) top

y-coordinate of the top



158
159
160
# File 'lib/prawn/grid.rb', line 158

def top
  @top ||= total_height - ((height + grid.row_gutter) * @i.to_f)
end

- (Object) top_left

x,y coordinates of top left corner



168
169
170
# File 'lib/prawn/grid.rb', line 168

def top_left
  [left, top]
end

- (Object) top_right

x,y coordinates of top right corner



173
174
175
# File 'lib/prawn/grid.rb', line 173

def top_right
  [right, top]
end

- (Object) total_height

:nodoc



128
129
130
# File 'lib/prawn/grid.rb', line 128

def total_height
  pdf.bounds.height.to_f
end

- (Object) width

Width of a box



133
134
135
# File 'lib/prawn/grid.rb', line 133

def width
  grid.column_width.to_f
end