lib/prawn/table/cells.rb in prawn-0.13.2 vs lib/prawn/table/cells.rb in prawn-0.14.0
- old
+ new
@@ -238,10 +238,13 @@
index = cell.send(row_or_column)
values[index] = [values[index], cell.send(meth)].compact.send(aggregate)
end
end
+ #if there are only colspanned or rowspanned cells in a table
+ spanned_width_needs_fixing = true
+
each do |cell|
index = cell.send(row_or_column)
if cell.colspan > 1
#calculate current (old) return value before we do anything
old_sum = 0
@@ -249,22 +252,23 @@
old_sum += values[index+i] unless values[index+i].nil?
}
#calculate future return value
new_sum = cell.send(meth) * cell.colspan
+ spanned_width_needs_fixing = (new_sum > old_sum)
- if new_sum >= old_sum
+ if spanned_width_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
entries_exist = true
cell.colspan.times { |i| entries_exist = false if values[index+i].nil? }
cell.colspan.times { |i|
values[index+i] = cell.send(meth) if entries_exist
}
end
else
- if cell.class == Prawn::Table::Cell::SpanDummy
+ if spanned_width_needs_fixing && cell.class == Prawn::Table::Cell::SpanDummy
values[index] = [values[index], cell.send(meth)].compact.send(aggregate)
end
end
end
values.values.inject(0, &:+)