class Prawn::Table
def draw
Draws the table onto the document at the document's current y-position.
def draw with_position do # Reference bounds are the non-stretchy bounds used to decide when to # flow to a new column / page. ref_bounds = @pdf.reference_bounds # Determine whether we're at the top of the current bounds (margin box or # bounding box). If we're at the top, we couldn't gain any more room by # breaking to the next page -- this means, in particular, that if the # first row is taller than the margin box, we will only move to the next # page if we're below the top. Some floating-point tolerance is added to # the calculation. # # Note that we use the actual bounds, not the reference bounds. This is # because even if we are in a stretchy bounding box, flowing to the next # page will not buy us any space if we are at the top. # # initial_row_on_initial_page may return 0 (already at the top OR created # a new page) or -1 (enough space) started_new_page_at_row = initial_row_on_initial_page # The cell y-positions are based on an infinitely long canvas. The offset # keeps track of how much we have to add to the original, theoretical # y-position to get to the actual position on the current page. offset = @pdf.y # Duplicate each cell of the header row into @header_row so it can be # modified in before_rendering_page callbacks. @header_row = header_rows if @header # Track cells to be drawn on this page. They will all be drawn when this # page is finished. cells_this_page = [] @cells.each do |cell| if start_new_page?(cell, offset, ref_bounds) # draw cells on the current page and then start a new one # this will also add a header to the new page if a header is set # reset array of cells for the new page cells_this_page, offset = ink_and_draw_cells_and_start_new_page(cells_this_page, cell) # remember the current row for background coloring started_new_page_at_row = cell.row end # Set background color, if any. cell = set_background_color(cell, started_new_page_at_row) # add the current cell to the cells array for the current page cells_this_page << [cell, [cell.relative_x, cell.relative_y(offset)]] end # Draw the last page of cells ink_and_draw_cells(cells_this_page) @pdf.move_cursor_to(@cells.last.relative_y(offset) - @cells.last.height) end end