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

table column widths where not always correctly calculated - fixes bug reported under issue #628 #629

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/prawn/table/cells.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ def aggregate_cell_values(row_or_column, meth, aggregate)
end
end

#if there are only colspanned or rowspanned cells in a table
spanned_with_needs_fixing = true

each do |cell|
index = cell.send(row_or_column)
if cell.colspan > 1
Expand All @@ -251,8 +254,9 @@ def aggregate_cell_values(row_or_column, meth, aggregate)

#calculate future return value
new_sum = cell.send(meth) * cell.colspan
spanned_with_needs_fixing = (new_sum > old_sum)

if new_sum >= old_sum
if spanned_with_needs_fixing
#not entirely sure why we need this line, but with it the tests pass
values[index] = [values[index], cell.send(meth)].compact.send(aggregate)
#overwrite the old values with the new ones, but only if all entries existed
Expand All @@ -263,7 +267,7 @@ def aggregate_cell_values(row_or_column, meth, aggregate)
}
end
else
if cell.class == Prawn::Table::Cell::SpanDummy
if spanned_with_needs_fixing and cell.class == Prawn::Table::Cell::SpanDummy
values[index] = [values[index], cell.send(meth)].compact.send(aggregate)
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
end

describe "You can explicitly set the column widths and use a colspan > 1" do
it "should work with two different given colspans", :issue => 628 do
data = [
[" ", " ", " "],
[{:content=>" ", :colspan=>3}],
[" ", {:content=>" ", :colspan=>2}]
]
column_widths = [60, 240, 60]
pdf = Prawn::Document.new
#the next line raised an Prawn::Errors::CannotFit exception before issue 628 was fixed
table = Prawn::Table.new data, pdf, :column_widths => column_widths
table.column_widths.should == column_widths
end

it "should work with a colspan > 1 with given column_widths (issue #407)" do
#normal entries in line 1
data = [
Expand Down