Skip to content

Use indent instead of bounding_box to position table #114

@mojavelinux

Description

@mojavelinux

The use of bounding_box to position (aka align) the table breaks the subsequent use of indent.

Here's the scenario to reproduce:

  • An auto-width table with align set to :center or :right
  • Enough rows so that the table breaks across a page boundary
  • A call to indent around commands that advance to the next page

Observe that bounds.absolute_left after the call to indent is reduced by the size of indent, whereas it should be the same as it was before the table. The indentation is being removed twice.

Here's sample code to reproduce this problem:

require 'prawn/table'

Prawn::Document.generate 'test.pdf' do
  initial_absolute_left = bounds.absolute_left
  text 'paragraph'
  data = [['header row']] + ([['...']] * 30)
  table data, header: true, position: :right
  indent 20 do
    bounds.move_past_bottom
  end
  if bounds.absolute_left != initial_absolute_left
    warn 'bounds were not properly restored after call to indent'
  end
  text 'paragraph'
end

I believe the problem is caused by this logic in Prawn: https://github.com/prawnpdf/prawn/blob/c5842a27b15f912f2f0ad5818a9ef38992978b3c/lib/prawn/document.rb#L723-L727. The padding is being read from the wrong box. It should be read from the bounding box, but instead is read from the margin box.

The simple solution to this problem is to use indent instead of bounding_box to align the table. It has exactly the same result, but avoids the problematic interaction between the bounding_box and indent functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions