prawnpdf / prawn-table

Provides support for tables in Prawn
Other
205 stars 98 forks source link

Use indent instead of bounding_box to position table #114

Open mojavelinux opened 5 years ago

mojavelinux commented 5 years ago

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

Here's the scenario to reproduce:

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.

mojavelinux commented 5 years ago

The other solution to the problem is to fix the logic to restore the indent padding in Prawn.

mojavelinux commented 5 years ago

Here's the upstream issue: https://github.com/prawnpdf/prawn/issues/1121

mojavelinux commented 5 years ago

PR sent. See #115.