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

Calculating table width broken when using an array of widths #710

Closed
skandragon opened this issue Apr 19, 2014 · 4 comments · Fixed by #712
Closed

Calculating table width broken when using an array of widths #710

skandragon opened this issue Apr 19, 2014 · 4 comments · Fixed by #712
Assignees

Comments

@skandragon
Copy link

This code does not properly run on 1.0.0, with the error

prawn-1.0.0/lib/prawn/table.rb:406:in `column_widths': Table's width was set larger than its contents' maximum width (max width 210, requested 218.0) (Prawn::Errors::CannotFit)
require 'rubygems'

require 'prawn'

PARTIAL_WIDTH = 40

Prawn::Document.generate("prawn-0004.pdf", page_size: "LETTER", page_layout: :portrait) do
  col_widths = [
    50,
    PARTIAL_WIDTH, PARTIAL_WIDTH, PARTIAL_WIDTH, PARTIAL_WIDTH
  ]

  day_header = [{
      content: "Monday, August 5th, A.S. XLIX",
      colspan: 5,
  }]

  times = [{
    content: "Loc",
    colspan: 1,
  }, {
    content: "8:00",
    colspan: 4,
  }]

  table_data = [ day_header ] + [ times ]

  table(table_data, column_widths: col_widths)
end


@practicingruby
Copy link
Member

@hbrandl ping

@hbrandl hbrandl self-assigned this Apr 21, 2014
@hbrandl
Copy link
Contributor

hbrandl commented Apr 21, 2014

I can confirm the bug report.

Testcase

    it "illustrates issue #710", :unresolved, :issue => 710 do
      partial_width = 40
      pdf = Prawn::Document.new({page_size: "LETTER", page_layout: :portrait})
      col_widths = [
        50,
        partial_width, partial_width, partial_width, partial_width
      ]

      day_header = [{
          content: "Monday, August 5th, A.S. XLIX",
          colspan: 5,
      }]

      times = [{
        content: "Loc",
        colspan: 1,
      }, {
        content: "8:00",
        colspan: 4,
      }]

      data = [ day_header ] + [ times ]

      #raises Prawn::Errors::CannotFit:
      #Table's width was set larger than its contents' maximum width (max width 210, requested 218.0)
      table = Prawn::Table.new data, pdf, :column_widths => col_widths
    end

I'll look into it and keep you updated.

hbrandl added a commit that referenced this issue Apr 21, 2014
refactoring code from cells.rb to column_width_calculator, from now on
all complex width related code is in this file.
fixed #710 be eliminating an edge case as reported under issue #710
@hbrandl
Copy link
Contributor

hbrandl commented Apr 21, 2014

Fixed with pull request 712.

@sandal please review and merge

The problem was that only column 0 ever existed by itself. Column 1 to 4 where always merged. While I don't see a use case where this may be necessary, I do think that this error is still raised unexpectedly thus I fixed it.

@practicingruby
Copy link
Member

Thanks @hbrandl.

@skandragon Can you try the code on the issue_710 branch and see if it fixes your problem?

practicingruby added a commit that referenced this issue May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants