Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use indent instead of bounding_box to position table #114

Open
mojavelinux opened this issue Jul 25, 2019 · 3 comments
Open

Use indent instead of bounding_box to position table #114

mojavelinux opened this issue Jul 25, 2019 · 3 comments

Comments

@mojavelinux
Copy link
Contributor

mojavelinux commented Jul 25, 2019

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.

@mojavelinux
Copy link
Contributor Author

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

@mojavelinux
Copy link
Contributor Author

mojavelinux commented Jul 25, 2019

Here's the upstream issue: prawnpdf/prawn#1121

@mojavelinux mojavelinux changed the title Use indent instead of bounding_box to align table Use indent instead of bounding_box to position table Jul 25, 2019
mojavelinux added a commit to mojavelinux/prawn-table that referenced this issue Jul 25, 2019
…_box

- position table using indent instead of align
- don't attempt to position table if table spans width of bounds
@mojavelinux
Copy link
Contributor Author

PR sent. See #115.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant