Object
Low level layout helper that simplifies coordinate math.
See Prawn::Document#bounding_box for a description of what this class is used for.
Template methods to support ColumnBox extensions
Absolute bottom y-coordinate of the bottom box
# File lib/prawn/document/bounding_box.rb, line 392
392: def absolute_bottom
393: @y - height
394: end
Absolute bottom-left point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 410
410: def absolute_bottom_left
411: [absolute_left, absolute_bottom]
412: end
Absolute bottom-left point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 416
416: def absolute_bottom_right
417: [absolute_right, absolute_bottom]
418: end
Absolute left x-coordinate of the bounding box
# File lib/prawn/document/bounding_box.rb, line 374
374: def absolute_left
375: @x
376: end
Absolute right x-coordinate of the bounding box
# File lib/prawn/document/bounding_box.rb, line 380
380: def absolute_right
381: @x + width
382: end
Absolute top y-coordinate of the bounding box
# File lib/prawn/document/bounding_box.rb, line 386
386: def absolute_top
387: @y
388: end
Absolute top-left point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 398
398: def absolute_top_left
399: [absolute_left, absolute_top]
400: end
Absolute top-right point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 404
404: def absolute_top_right
405: [absolute_right, absolute_top]
406: end
Increase the left padding of the bounding box.
# File lib/prawn/document/bounding_box.rb, line 267
267: def add_left_padding(left_padding)
268: @total_left_padding += left_padding
269: @x += left_padding
270: @width -= left_padding
271: end
Increase the right padding of the bounding box.
# File lib/prawn/document/bounding_box.rb, line 281
281: def add_right_padding(right_padding)
282: @total_right_padding += right_padding
283: @width -= right_padding
284: end
The translated origin (x,y-height) which describes the location of the bottom left corner of the bounding box
# File lib/prawn/document/bounding_box.rb, line 227
227: def anchor
228: [@x, @y - height]
229: end
Relative bottom y-coordinate of the bounding box (Always 0)
Example, position some text 3 pts from the bottom of the containing box:
draw_text('hello', :at => [0, (bounds.bottom + 3)])
# File lib/prawn/document/bounding_box.rb, line 318
318: def bottom
319: 0
320: end
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
# File lib/prawn/document/bounding_box.rb, line 368
368: def bottom_left
369: [left,bottom]
370: end
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
# File lib/prawn/document/bounding_box.rb, line 356
356: def bottom_right
357: [right,bottom]
358: end
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.
# File lib/prawn/document/bounding_box.rb, line 430
430: def height
431: return @height if @height
432: @stretched_height = [(absolute_top - @document.y),
433: @stretched_height.to_f].max
434: end
Temporarily adjust the @x coordinate to allow for left_padding
Example:
indent 20 do
text "20 points in"
indent 30 do
text "50 points in"
end
end
indent 20, 20 do
text "indented on both sides"
end
# File lib/prawn/document/bounding_box.rb, line 257
257: def indent(left_padding, right_padding = 0, &block)
258: add_left_padding(left_padding)
259: add_right_padding(right_padding)
260: yield
261: ensure
262: @document.bounds.subtract_left_padding(left_padding)
263: @document.bounds.subtract_right_padding(right_padding)
264: end
Relative left x-coordinate of the bounding box. (Always 0)
Example, position some text 3 pts from the left of the containing box:
draw_text('hello', :at => [(bounds.left + 3), 0])
# File lib/prawn/document/bounding_box.rb, line 237
237: def left
238: 0
239: end
an alias for absolute_left
# File lib/prawn/document/bounding_box.rb, line 437
437: def left_side
438: absolute_left
439: end
an alias for absolute_left
# File lib/prawn/document/column_box.rb, line 48
48: def left_side
49: absolute_left
50: end
starts a new page
# File lib/prawn/document/bounding_box.rb, line 447
447: def move_past_bottom
448: @document.start_new_page
449: end
starts a new page
# File lib/prawn/document/column_box.rb, line 58
58: def move_past_bottom
59: @document.start_new_page
60: end
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:
draw_text('hello', :at => [(bounds.right - 3), 0])
# File lib/prawn/document/bounding_box.rb, line 298
298: def right
299: @width
300: end
an alias for absolute_right
# File lib/prawn/document/column_box.rb, line 53
53: def right_side
54: absolute_right
55: end
an alias for absolute_right
# File lib/prawn/document/bounding_box.rb, line 442
442: def right_side
443: absolute_right
444: end
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.
# File lib/prawn/document/bounding_box.rb, line 457
457: def stretchy?
458: !@height
459: end
Decrease the left padding of the bounding box.
# File lib/prawn/document/bounding_box.rb, line 274
274: def subtract_left_padding(left_padding)
275: @total_left_padding -= left_padding
276: @x -= left_padding
277: @width += left_padding
278: end
Decrease the right padding of the bounding box.
# File lib/prawn/document/bounding_box.rb, line 287
287: def subtract_right_padding(right_padding)
288: @total_right_padding -= right_padding
289: @width += right_padding
290: end
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:
draw_text('hello', :at => [0, (bounds.top - 3)])
# File lib/prawn/document/bounding_box.rb, line 308
308: def top
309: height
310: end
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.top_left, bounds.bottom_right) end
# File lib/prawn/document/bounding_box.rb, line 331
331: def top_left
332: [left,top]
333: end
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
# File lib/prawn/document/bounding_box.rb, line 344
344: def top_right
345: [right,top]
346: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.