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.



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

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

Instance Attribute Details

#pdfObject (readonly)

:nodoc:



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

def pdf
  @pdf
end

Instance Method Details

#bottomObject

y-coordinate of the bottom



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

def bottom
  @bottom ||= top - height
end

#bottom_leftObject

x,y coordinates of bottom left corner



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

def bottom_left
  [left, bottom]
end

#bottom_rightObject

x,y coordinates of bottom right corner



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

def bottom_right
  [right, bottom]
end

#bounding_box(&blk) ⇒ Object

Creates a standard bounding box based on the grid box.



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

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

#gutterObject

Width of the gutter



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

def gutter
  grid.gutter.to_f
end

#heightObject

Height of a box



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

def height
  grid.row_height.to_f
end

#leftObject

x-coordinate of left side



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

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



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

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

#rightObject

x-coordinate of right side



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

def right
  @right ||= left + width
end

#show(grid_color = "CCCCCC") ⇒ Object

Diagnostic method



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

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



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

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

#top_leftObject

x,y coordinates of top left corner



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

def top_left
  [left, top]
end

#top_rightObject

x,y coordinates of top right corner



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

def top_right
  [right, top]
end

#total_heightObject

:nodoc



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

def total_height
  pdf.bounds.height.to_f
end

#widthObject

Width of a box



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

def width
  grid.column_width.to_f
end