Class: Prawn::Document::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/layout/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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, i, j) ⇒ Box

Returns a new instance of Box.



93
94
95
96
97
# File 'lib/prawn/layout/grid.rb', line 93

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

Instance Attribute Details

#pdfObject (readonly)

Returns the value of attribute pdf.



91
92
93
# File 'lib/prawn/layout/grid.rb', line 91

def pdf
  @pdf
end

Instance Method Details

#bottomObject

y-coordinate of the bottom



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

def bottom
  @bottom ||= top - height
end

#bottom_leftObject

x,y coordinates of bottom left corner



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

def bottom_left
  [left, bottom]
end

#bottom_rightObject

x,y coordinates of bottom right corner



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

def bottom_right
  [right, bottom]
end

#bounding_box(&blk) ⇒ Object

Creates a standard bounding box based on the grid box.



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

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

#gutterObject

Width of the gutter



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

def gutter
  grid.gutter.to_f
end

#heightObject

Height of a box



117
118
119
# File 'lib/prawn/layout/grid.rb', line 117

def height
  grid.row_height.to_f
end

#leftObject

x-coordinate of left side



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

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

#nameObject

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



102
103
104
# File 'lib/prawn/layout/grid.rb', line 102

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

#rightObject

x-coordinate of right side



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

def right
  @right ||= left + width
end

#show(grid_color = "CCCCCC") ⇒ Object

Diagnostic method



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/prawn/layout/grid.rb', line 172

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

#topObject

y-coordinate of the top



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

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

#top_leftObject

x,y coordinates of top left corner



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

def top_left
  [left, top]
end

#top_rightObject

x,y coordinates of top right corner



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

def top_right
  [right, top]
end

#total_heightObject

:nodoc



107
108
109
# File 'lib/prawn/layout/grid.rb', line 107

def total_height
  pdf.bounds.height.to_f
end

#widthObject

Width of a box



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

def width
  grid.column_width.to_f
end