prawn-table icon indicating copy to clipboard operation
prawn-table copied to clipboard

Layout error for tables with vertical span cells

Open rillbert opened this issue 7 years ago • 0 comments

Steps-to-reproduce

  1. Create a document with a table where the first row contains a cell with vertical span.
  2. Taylor the document in such a way that the cell with vertical span does not fit between the current rendering position on a page and the bottom margin.
  3. Render the document.

Expected Result

  • The table should be drawn from the top of a new page.

ok.pdf

Actual Result

  • the table's first row is split. The cell with the vertical spacing is rendered on the page where it does not fit and the rest of the row is rendered on the next page without regard to the top margin. Note that the second table in the example docs renders ok in both cases since the complete vertical span cell fit within the remaining vertical space on that page.

error.pdf

Probable cause

In file Table.rb, the following code exists


def initial_row_on_initial_page
  # we're at the top of our bounds
  return 0 if fits_on_page?(@pdf.bounds.height)

  needed_height = row(0..number_of_header_rows).height

needed_height is calculated without consideration to vertical span.

Proposed fix:

Change the above to:


def initial_row_on_initial_page
  # we're at the top of our bounds
  return 0 if fits_on_page?(@pdf.bounds.height)

  needed_height = row(0..number_of_header_rows).height_with_span

to account for vertical span.

Both of the above pdf's were rendered via asciidoctor-pdf from the same asciidoc source, one with, one without the fix above. The reason I used asciidoctor-pdf is that I don't have any experience of working directly with prawn-pdf so this was the quickest way for me to render the example docs.

I managed to create a pull request with the above fix (I hope...)

Cheers /Anders

rillbert avatar Aug 17 '18 20:08 rillbert