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 353 def absolute_bottom @y - height end
Absolute bottom-left point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 371 def absolute_bottom_left [absolute_left, absolute_bottom] end
Absolute bottom-left point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 377 def absolute_bottom_right [absolute_right, absolute_bottom] end
Absolute left x-coordinate of the bounding box
# File lib/prawn/document/bounding_box.rb, line 335 def absolute_left @x end
Absolute right x-coordinate of the bounding box
# File lib/prawn/document/bounding_box.rb, line 341 def absolute_right @x + width end
Absolute top y-coordinate of the bounding box
# File lib/prawn/document/bounding_box.rb, line 347 def absolute_top @y end
Absolute top-left point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 359 def absolute_top_left [absolute_left, absolute_top] end
Absolute top-right point of the bounding box
# File lib/prawn/document/bounding_box.rb, line 365 def absolute_top_right [absolute_right, absolute_top] 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 218 def anchor [@x, @y - height] 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 279 def bottom 0 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 329 def bottom_left [left,bottom] 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 317 def bottom_right [right,bottom] 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 391 def height return @height if @height @stretched_height = [(absolute_top - @parent.y), @stretched_height.to_f].max 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
# File lib/prawn/document/bounding_box.rb, line 244 def indent(left_padding, &block) @x += left_padding @width -= left_padding yield ensure @x -= left_padding @width += left_padding 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 228 def left 0 end
an alias for #absolute_left
# File lib/prawn/document/column_box.rb, line 48 def left_side absolute_left end
starts a new page
# File lib/prawn/document/column_box.rb, line 58 def move_past_bottom @parent.start_new_page 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 259 def right @width end
an alias for #absolute_right
# File lib/prawn/document/column_box.rb, line 53 def right_side absolute_right 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 401 def stretchy? !@height 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 269 def top height 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., bounds.bottom_right) end
# File lib/prawn/document/bounding_box.rb, line 292 def top_left [left,top] 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 305 def top_right [right,top] end
Width of the bounding box
# File lib/prawn/document/bounding_box.rb, line 383 def width @width end