Class: Prawn::Document::BoundingBox

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

Direct Known Subclasses

ColumnBox

Instance Method Summary collapse

Constructor Details

#initialize(parent, point, options = {}) ⇒ BoundingBox

:nodoc:



190
191
192
193
194
# File 'lib/prawn/document/bounding_box.rb', line 190

def initialize(parent, point, options={}) #:nodoc:   
  @parent = parent
  @x, @y = point
  @width, @height = options[:width], options[:height]
end

Instance Method Details

#absolute_bottomObject

Absolute bottom y-coordinate of the bottom box



313
314
315
# File 'lib/prawn/document/bounding_box.rb', line 313

def absolute_bottom
  @y - height
end

#absolute_bottom_leftObject

Absolute bottom-left point of the bounding box



331
332
333
# File 'lib/prawn/document/bounding_box.rb', line 331

def absolute_bottom_left
  [absolute_left, absolute_bottom]
end

#absolute_bottom_rightObject

Absolute bottom-left point of the bounding box



337
338
339
# File 'lib/prawn/document/bounding_box.rb', line 337

def absolute_bottom_right
  [absolute_right, absolute_bottom]
end

#absolute_leftObject

Absolute left x-coordinate of the bounding box



295
296
297
# File 'lib/prawn/document/bounding_box.rb', line 295

def absolute_left
  @x
end

#absolute_rightObject

Absolute right x-coordinate of the bounding box



301
302
303
# File 'lib/prawn/document/bounding_box.rb', line 301

def absolute_right
  @x + width
end

#absolute_topObject

Absolute top y-coordinate of the bounding box



307
308
309
# File 'lib/prawn/document/bounding_box.rb', line 307

def absolute_top
  @y
end

#absolute_top_leftObject

Absolute top-left point of the bounding box



319
320
321
# File 'lib/prawn/document/bounding_box.rb', line 319

def absolute_top_left
  [absolute_left, absolute_top]
end

#absolute_top_rightObject

Absolute top-right point of the bounding box



325
326
327
# File 'lib/prawn/document/bounding_box.rb', line 325

def absolute_top_right
  [absolute_right, absolute_top]
end

#anchorObject

The translated origin (x,y-height) which describes the location of the bottom left corner of the bounding box



199
200
201
# File 'lib/prawn/document/bounding_box.rb', line 199

def anchor
  [@x, @y - height]
end

#bottomObject

Relative bottom y-coordinate of the bounding box (Always 0)

Example, position some text 3 pts from the bottom of the containing box:

text('hello', :at => [0, (bounds.bottom + 3)])


239
240
241
# File 'lib/prawn/document/bounding_box.rb', line 239

def bottom
  0
end

#bottom_leftObject

Relative bottom-left point of the bounding box

Example, draw a line along the left hand side of the page:

stroke do
  line(bounds.bottom_left, bounds.top_left)
end


289
290
291
# File 'lib/prawn/document/bounding_box.rb', line 289

def bottom_left
  [left,bottom]
end

#bottom_rightObject

Relative bottom-right point of the bounding box

Example, draw a line along the right hand side of the page:

stroke do
  line(bounds.bottom_right, bounds.top_right)
end


277
278
279
# File 'lib/prawn/document/bounding_box.rb', line 277

def bottom_right
  [right,bottom]
end

#heightObject

Height of the bounding box. If the box is ‘stretchy’ (unspecified height attribute), height is calculated as the distance from the top of the box to the current drawing position.



351
352
353
# File 'lib/prawn/document/bounding_box.rb', line 351

def height  
  @height || absolute_top - @parent.y
end

#leftObject

Relative left x-coordinate of the bounding box. (Always 0)

Example, position some text 3 pts from the left of the containing box:

text('hello', :at => [(bounds.left + 3), 0])


209
210
211
# File 'lib/prawn/document/bounding_box.rb', line 209

def left
  0
end

#left_sideObject



362
363
364
# File 'lib/prawn/document/bounding_box.rb', line 362

def left_side
   absolute_left
end

#move_past_bottomObject



370
371
372
# File 'lib/prawn/document/bounding_box.rb', line 370

def move_past_bottom
   @parent.start_new_page
end

#rightObject

Relative right x-coordinate of the bounding box. (Equal to the box width)

Example, position some text 3 pts from the right of the containing box:

text('hello', :at => [(bounds.right - 3), 0])


219
220
221
# File 'lib/prawn/document/bounding_box.rb', line 219

def right
  @width
end

#right_sideObject



366
367
368
# File 'lib/prawn/document/bounding_box.rb', line 366

def right_side
   absolute_right
end

#stretchy?Boolean

Returns false when the box has a defined height, true when the height is being calculated on the fly based on the current vertical position.

Returns:

  • (Boolean)


358
359
360
# File 'lib/prawn/document/bounding_box.rb', line 358

def stretchy?
  !@height 
end

#topObject

Relative top y-coordinate of the bounding box. (Equal to the box height)

Example, position some text 3 pts from the top of the containing box:

text('hello', :at => [0, (bounds.top - 3)])


229
230
231
# File 'lib/prawn/document/bounding_box.rb', line 229

def top
  height
end

#top_leftObject

Relative top-left point of the bounding_box

Example, draw a line from the top left of the box diagonally to the bottom right:

stroke do
  line(bounds., bounds.bottom_right)
end


252
253
254
# File 'lib/prawn/document/bounding_box.rb', line 252

def top_left
  [left,top]
end

#top_rightObject

Relative top-right point of the bounding box

Example, draw a line from the top_right of the box diagonally to the bottom left:

stroke do
  line(bounds.top_right, bounds.bottom_left)
end


265
266
267
# File 'lib/prawn/document/bounding_box.rb', line 265

def top_right
  [right,top]
end

#widthObject

Width of the bounding box



343
344
345
# File 'lib/prawn/document/bounding_box.rb', line 343

def width
  @width
end